mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-25 07:16:51 +00:00
4707
electron/assets/wasm/wasm_video_decode.js
Normal file
4707
electron/assets/wasm/wasm_video_decode.js
Normal file
File diff suppressed because it is too large
Load Diff
BIN
electron/assets/wasm/wasm_video_decode.wasm
Normal file
BIN
electron/assets/wasm/wasm_video_decode.wasm
Normal file
Binary file not shown.
@@ -18,7 +18,7 @@ import { exportService, ExportOptions, ExportProgress } from './services/exportS
|
|||||||
import { KeyService } from './services/keyService'
|
import { KeyService } from './services/keyService'
|
||||||
import { voiceTranscribeService } from './services/voiceTranscribeService'
|
import { voiceTranscribeService } from './services/voiceTranscribeService'
|
||||||
import { videoService } from './services/videoService'
|
import { videoService } from './services/videoService'
|
||||||
import { snsService } from './services/snsService'
|
import { snsService, isVideoUrl } from './services/snsService'
|
||||||
import { contactExportService } from './services/contactExportService'
|
import { contactExportService } from './services/contactExportService'
|
||||||
import { windowsHelloService } from './services/windowsHelloService'
|
import { windowsHelloService } from './services/windowsHelloService'
|
||||||
import { llamaService } from './services/llamaService'
|
import { llamaService } from './services/llamaService'
|
||||||
@@ -104,7 +104,8 @@ function createWindow(options: { autoShow?: boolean } = {}) {
|
|||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: join(__dirname, 'preload.js'),
|
preload: join(__dirname, 'preload.js'),
|
||||||
contextIsolation: true,
|
contextIsolation: true,
|
||||||
nodeIntegration: false
|
nodeIntegration: false,
|
||||||
|
webSecurity: false // Allow loading local files (video playback)
|
||||||
},
|
},
|
||||||
titleBarStyle: 'hidden',
|
titleBarStyle: 'hidden',
|
||||||
titleBarOverlay: {
|
titleBarOverlay: {
|
||||||
@@ -932,8 +933,46 @@ function registerIpcHandlers() {
|
|||||||
return snsService.debugResource(url)
|
return snsService.debugResource(url)
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.handle('sns:proxyImage', async (_, url: string) => {
|
ipcMain.handle('sns:proxyImage', async (_, payload: string | { url: string; key?: string | number }) => {
|
||||||
return snsService.proxyImage(url)
|
const url = typeof payload === 'string' ? payload : payload?.url
|
||||||
|
const key = typeof payload === 'string' ? undefined : payload?.key
|
||||||
|
return snsService.proxyImage(url, key)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('sns:downloadImage', async (_, payload: { url: string; key?: string | number }) => {
|
||||||
|
try {
|
||||||
|
const { url, key } = payload
|
||||||
|
const result = await snsService.downloadImage(url, key)
|
||||||
|
|
||||||
|
if (!result.success || !result.data) {
|
||||||
|
return { success: false, error: result.error || '下载图片失败' }
|
||||||
|
}
|
||||||
|
|
||||||
|
const { dialog } = await import('electron')
|
||||||
|
const ext = (result.contentType || '').split('/')[1] || 'jpg'
|
||||||
|
const defaultPath = `SNS_${Date.now()}.${ext}`
|
||||||
|
|
||||||
|
|
||||||
|
const filters = isVideoUrl(url)
|
||||||
|
? [{ name: 'Videos', extensions: ['mp4', 'mov', 'avi', 'mkv'] }]
|
||||||
|
: [{ name: 'Images', extensions: [ext, 'jpg', 'jpeg', 'png', 'webp', 'gif'] }]
|
||||||
|
|
||||||
|
const { filePath, canceled } = await dialog.showSaveDialog({
|
||||||
|
defaultPath,
|
||||||
|
filters
|
||||||
|
})
|
||||||
|
|
||||||
|
if (canceled || !filePath) {
|
||||||
|
return { success: false, error: '用户已取消' }
|
||||||
|
}
|
||||||
|
|
||||||
|
const fs = await import('fs/promises')
|
||||||
|
await fs.writeFile(filePath, result.data)
|
||||||
|
|
||||||
|
return { success: true, filePath }
|
||||||
|
} catch (e) {
|
||||||
|
return { success: false, error: String(e) }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 私聊克隆
|
// 私聊克隆
|
||||||
|
|||||||
@@ -271,7 +271,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
|||||||
getTimeline: (limit: number, offset: number, usernames?: string[], keyword?: string, startTime?: number, endTime?: number) =>
|
getTimeline: (limit: number, offset: number, usernames?: string[], keyword?: string, startTime?: number, endTime?: number) =>
|
||||||
ipcRenderer.invoke('sns:getTimeline', limit, offset, usernames, keyword, startTime, endTime),
|
ipcRenderer.invoke('sns:getTimeline', limit, offset, usernames, keyword, startTime, endTime),
|
||||||
debugResource: (url: string) => ipcRenderer.invoke('sns:debugResource', url),
|
debugResource: (url: string) => ipcRenderer.invoke('sns:debugResource', url),
|
||||||
proxyImage: (url: string) => ipcRenderer.invoke('sns:proxyImage', url)
|
proxyImage: (payload: { url: string; key?: string | number }) => ipcRenderer.invoke('sns:proxyImage', payload),
|
||||||
|
downloadImage: (payload: { url: string; key?: string | number }) => ipcRenderer.invoke('sns:downloadImage', payload)
|
||||||
},
|
},
|
||||||
|
|
||||||
// Llama AI
|
// Llama AI
|
||||||
|
|||||||
@@ -141,10 +141,10 @@ class ChatService {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.configService = new ConfigService()
|
this.configService = new ConfigService()
|
||||||
this.contactCacheService = new ContactCacheService(this.configService.get('cachePath'))
|
this.contactCacheService = new ContactCacheService(this.configService.getCacheBasePath())
|
||||||
const persisted = this.contactCacheService.getAllEntries()
|
const persisted = this.contactCacheService.getAllEntries()
|
||||||
this.avatarCache = new Map(Object.entries(persisted))
|
this.avatarCache = new Map(Object.entries(persisted))
|
||||||
this.messageCacheService = new MessageCacheService(this.configService.get('cachePath'))
|
this.messageCacheService = new MessageCacheService(this.configService.getCacheBasePath())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { join } from 'path'
|
||||||
|
import { app } from 'electron'
|
||||||
import Store from 'electron-store'
|
import Store from 'electron-store'
|
||||||
|
|
||||||
interface ConfigSchema {
|
interface ConfigSchema {
|
||||||
@@ -12,6 +14,7 @@ interface ConfigSchema {
|
|||||||
|
|
||||||
// 缓存相关
|
// 缓存相关
|
||||||
cachePath: string
|
cachePath: string
|
||||||
|
weixinDllPath: string
|
||||||
lastOpenedDb: string
|
lastOpenedDb: string
|
||||||
lastSession: string
|
lastSession: string
|
||||||
|
|
||||||
@@ -72,6 +75,7 @@ export class ConfigService {
|
|||||||
imageAesKey: '',
|
imageAesKey: '',
|
||||||
wxidConfigs: {},
|
wxidConfigs: {},
|
||||||
cachePath: '',
|
cachePath: '',
|
||||||
|
weixinDllPath: '',
|
||||||
lastOpenedDb: '',
|
lastOpenedDb: '',
|
||||||
lastSession: '',
|
lastSession: '',
|
||||||
theme: 'system',
|
theme: 'system',
|
||||||
@@ -109,6 +113,14 @@ export class ConfigService {
|
|||||||
this.store.set(key, value)
|
this.store.set(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCacheBasePath(): string {
|
||||||
|
const configured = this.get('cachePath')
|
||||||
|
if (configured && configured.trim().length > 0) {
|
||||||
|
return configured
|
||||||
|
}
|
||||||
|
return join(app.getPath('documents'), 'WeFlow')
|
||||||
|
}
|
||||||
|
|
||||||
getAll(): ConfigSchema {
|
getAll(): ConfigSchema {
|
||||||
return this.store.store
|
return this.store.store
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { join, dirname } from 'path'
|
import { join, dirname } from 'path'
|
||||||
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs'
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs'
|
||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
|
import { ConfigService } from './config'
|
||||||
|
|
||||||
export interface ContactCacheEntry {
|
export interface ContactCacheEntry {
|
||||||
displayName?: string
|
displayName?: string
|
||||||
@@ -15,7 +16,7 @@ export class ContactCacheService {
|
|||||||
constructor(cacheBasePath?: string) {
|
constructor(cacheBasePath?: string) {
|
||||||
const basePath = cacheBasePath && cacheBasePath.trim().length > 0
|
const basePath = cacheBasePath && cacheBasePath.trim().length > 0
|
||||||
? cacheBasePath
|
? cacheBasePath
|
||||||
: join(app.getPath('documents'), 'WeFlow')
|
: ConfigService.getInstance().getCacheBasePath()
|
||||||
this.cacheFilePath = join(basePath, 'contacts.json')
|
this.cacheFilePath = join(basePath, 'contacts.json')
|
||||||
this.ensureCacheDir()
|
this.ensureCacheDir()
|
||||||
this.loadCache()
|
this.loadCache()
|
||||||
|
|||||||
@@ -4512,7 +4512,7 @@ class ExportService {
|
|||||||
phase: 'exporting'
|
phase: 'exporting'
|
||||||
})
|
})
|
||||||
|
|
||||||
const safeName = sessionInfo.displayName.replace(/[<>:"/\\|?*]/g, '_')
|
const safeName = sessionInfo.displayName.replace(/[<>:"\/\\|?*]/g, '_').replace(/\.+$/, '')
|
||||||
const useSessionFolder = sessionLayout === 'per-session'
|
const useSessionFolder = sessionLayout === 'per-session'
|
||||||
const sessionDir = useSessionFolder ? path.join(outputDir, safeName) : outputDir
|
const sessionDir = useSessionFolder ? path.join(outputDir, safeName) : outputDir
|
||||||
|
|
||||||
|
|||||||
121
electron/services/isaac64.ts
Normal file
121
electron/services/isaac64.ts
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/**
|
||||||
|
* ISAAC-64: A fast cryptographic PRNG
|
||||||
|
* Re-implemented in TypeScript using BigInt for 64-bit support.
|
||||||
|
* Used for WeChat Channels/SNS video decryption.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class Isaac64 {
|
||||||
|
private mm = new BigUint64Array(256);
|
||||||
|
private aa = 0n;
|
||||||
|
private bb = 0n;
|
||||||
|
private cc = 0n;
|
||||||
|
private randrsl = new BigUint64Array(256);
|
||||||
|
private randcnt = 0;
|
||||||
|
private static readonly MASK = 0xFFFFFFFFFFFFFFFFn;
|
||||||
|
|
||||||
|
constructor(seed: number | string | bigint) {
|
||||||
|
const seedBig = BigInt(seed);
|
||||||
|
// 通常单密钥初始化是将密钥放在第一个槽位,其余清零(或者按某种规律填充)
|
||||||
|
// 这里我们尝试仅设置第一个槽位,这在很多 WASM 移植版本中更为常见
|
||||||
|
this.randrsl.fill(0n);
|
||||||
|
this.randrsl[0] = seedBig;
|
||||||
|
this.init(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(flag: boolean) {
|
||||||
|
let a: bigint, b: bigint, c: bigint, d: bigint, e: bigint, f: bigint, g: bigint, h: bigint;
|
||||||
|
a = b = c = d = e = f = g = h = 0x9e3779b97f4a7c15n;
|
||||||
|
|
||||||
|
const mix = () => {
|
||||||
|
a = (a - e) & Isaac64.MASK; f ^= (h >> 9n); h = (h + a) & Isaac64.MASK;
|
||||||
|
b = (b - f) & Isaac64.MASK; g ^= (a << 9n) & Isaac64.MASK; a = (a + b) & Isaac64.MASK;
|
||||||
|
c = (c - g) & Isaac64.MASK; h ^= (b >> 23n); b = (b + c) & Isaac64.MASK;
|
||||||
|
d = (d - h) & Isaac64.MASK; a ^= (c << 15n) & Isaac64.MASK; c = (c + d) & Isaac64.MASK;
|
||||||
|
e = (e - a) & Isaac64.MASK; b ^= (d >> 14n); d = (d + e) & Isaac64.MASK;
|
||||||
|
f = (f - b) & Isaac64.MASK; c ^= (e << 20n) & Isaac64.MASK; e = (e + f) & Isaac64.MASK;
|
||||||
|
g = (g - c) & Isaac64.MASK; d ^= (f >> 17n); f = (f + g) & Isaac64.MASK;
|
||||||
|
h = (h - d) & Isaac64.MASK; e ^= (g << 14n) & Isaac64.MASK; g = (g + h) & Isaac64.MASK;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let i = 0; i < 4; i++) mix();
|
||||||
|
|
||||||
|
for (let i = 0; i < 256; i += 8) {
|
||||||
|
if (flag) {
|
||||||
|
a = (a + this.randrsl[i]) & Isaac64.MASK;
|
||||||
|
b = (b + this.randrsl[i + 1]) & Isaac64.MASK;
|
||||||
|
c = (c + this.randrsl[i + 2]) & Isaac64.MASK;
|
||||||
|
d = (d + this.randrsl[i + 3]) & Isaac64.MASK;
|
||||||
|
e = (e + this.randrsl[i + 4]) & Isaac64.MASK;
|
||||||
|
f = (f + this.randrsl[i + 5]) & Isaac64.MASK;
|
||||||
|
g = (g + this.randrsl[i + 6]) & Isaac64.MASK;
|
||||||
|
h = (h + this.randrsl[i + 7]) & Isaac64.MASK;
|
||||||
|
}
|
||||||
|
mix();
|
||||||
|
this.mm[i] = a; this.mm[i + 1] = b; this.mm[i + 2] = c; this.mm[i + 3] = d;
|
||||||
|
this.mm[i + 4] = e; this.mm[i + 5] = f; this.mm[i + 6] = g; this.mm[i + 7] = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
for (let i = 0; i < 256; i += 8) {
|
||||||
|
a = (a + this.mm[i]) & Isaac64.MASK;
|
||||||
|
b = (b + this.mm[i + 1]) & Isaac64.MASK;
|
||||||
|
c = (c + this.mm[i + 2]) & Isaac64.MASK;
|
||||||
|
d = (d + this.mm[i + 3]) & Isaac64.MASK;
|
||||||
|
e = (e + this.mm[i + 4]) & Isaac64.MASK;
|
||||||
|
f = (f + this.mm[i + 5]) & Isaac64.MASK;
|
||||||
|
g = (g + this.mm[i + 6]) & Isaac64.MASK;
|
||||||
|
h = (h + this.mm[i + 7]) & Isaac64.MASK;
|
||||||
|
mix();
|
||||||
|
this.mm[i] = a; this.mm[i + 1] = b; this.mm[i + 2] = c; this.mm[i + 3] = d;
|
||||||
|
this.mm[i + 4] = e; this.mm[i + 5] = f; this.mm[i + 6] = g; this.mm[i + 7] = h;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isaac64();
|
||||||
|
this.randcnt = 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
private isaac64() {
|
||||||
|
this.cc = (this.cc + 1n) & Isaac64.MASK;
|
||||||
|
this.bb = (this.bb + this.cc) & Isaac64.MASK;
|
||||||
|
for (let i = 0; i < 256; i++) {
|
||||||
|
let x = this.mm[i];
|
||||||
|
switch (i & 3) {
|
||||||
|
case 0: this.aa = (this.aa ^ (((this.aa << 21n) & Isaac64.MASK) ^ Isaac64.MASK)) & Isaac64.MASK; break;
|
||||||
|
case 1: this.aa = (this.aa ^ (this.aa >> 5n)) & Isaac64.MASK; break;
|
||||||
|
case 2: this.aa = (this.aa ^ ((this.aa << 12n) & Isaac64.MASK)) & Isaac64.MASK; break;
|
||||||
|
case 3: this.aa = (this.aa ^ (this.aa >> 33n)) & Isaac64.MASK; break;
|
||||||
|
}
|
||||||
|
this.aa = (this.mm[(i + 128) & 255] + this.aa) & Isaac64.MASK;
|
||||||
|
const y = (this.mm[Number(x >> 3n) & 255] + this.aa + this.bb) & Isaac64.MASK;
|
||||||
|
this.mm[i] = y;
|
||||||
|
this.bb = (this.mm[Number(y >> 11n) & 255] + x) & Isaac64.MASK;
|
||||||
|
this.randrsl[i] = this.bb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public getNext(): bigint {
|
||||||
|
if (this.randcnt === 0) {
|
||||||
|
this.isaac64();
|
||||||
|
this.randcnt = 256;
|
||||||
|
}
|
||||||
|
return this.randrsl[256 - (this.randcnt--)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a keystream of the specified size (in bytes).
|
||||||
|
* @param size Size of the keystream in bytes (must be multiple of 8)
|
||||||
|
* @returns Buffer containing the keystream
|
||||||
|
*/
|
||||||
|
public generateKeystream(size: number): Buffer {
|
||||||
|
const stream = new BigUint64Array(size / 8);
|
||||||
|
for (let i = 0; i < stream.length; i++) {
|
||||||
|
stream[i] = this.getNext();
|
||||||
|
}
|
||||||
|
// WeChat's logic specifically reverses the entire byte array
|
||||||
|
const buffer = Buffer.from(stream.buffer);
|
||||||
|
// 注意:根据 worker.html 的逻辑,它是对 Uint8Array 执行 reverse()
|
||||||
|
// Array.from(wasmArray).reverse()
|
||||||
|
return buffer.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { join, dirname } from 'path'
|
import { join, dirname } from 'path'
|
||||||
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs'
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs'
|
||||||
import { app } from 'electron'
|
import { app } from 'electron'
|
||||||
|
import { ConfigService } from './config'
|
||||||
|
|
||||||
export interface SessionMessageCacheEntry {
|
export interface SessionMessageCacheEntry {
|
||||||
updatedAt: number
|
updatedAt: number
|
||||||
@@ -15,7 +16,7 @@ export class MessageCacheService {
|
|||||||
constructor(cacheBasePath?: string) {
|
constructor(cacheBasePath?: string) {
|
||||||
const basePath = cacheBasePath && cacheBasePath.trim().length > 0
|
const basePath = cacheBasePath && cacheBasePath.trim().length > 0
|
||||||
? cacheBasePath
|
? cacheBasePath
|
||||||
: join(app.getPath('documents'), 'WeFlow')
|
: ConfigService.getInstance().getCacheBasePath()
|
||||||
this.cacheFilePath = join(basePath, 'session-messages.json')
|
this.cacheFilePath = join(basePath, 'session-messages.json')
|
||||||
this.ensureCacheDir()
|
this.ensureCacheDir()
|
||||||
this.loadCache()
|
this.loadCache()
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import { wcdbService } from './wcdbService'
|
import { wcdbService } from './wcdbService'
|
||||||
import { ConfigService } from './config'
|
import { ConfigService } from './config'
|
||||||
import { ContactCacheService } from './contactCacheService'
|
import { ContactCacheService } from './contactCacheService'
|
||||||
|
import { existsSync, mkdirSync } from 'fs'
|
||||||
|
import { readFile, writeFile, mkdir } from 'fs/promises'
|
||||||
|
import { basename, join } from 'path'
|
||||||
|
import crypto from 'crypto'
|
||||||
|
import { WasmService } from './wasmService'
|
||||||
|
|
||||||
export interface SnsLivePhoto {
|
export interface SnsLivePhoto {
|
||||||
url: string
|
url: string
|
||||||
@@ -32,82 +37,147 @@ export interface SnsPost {
|
|||||||
media: SnsMedia[]
|
media: SnsMedia[]
|
||||||
likes: string[]
|
likes: string[]
|
||||||
comments: { id: string; nickname: string; content: string; refCommentId: string; refNickname?: string }[]
|
comments: { id: string; nickname: string; content: string; refCommentId: string; refNickname?: string }[]
|
||||||
rawXml?: string // 原始 XML 数据
|
rawXml?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const fixSnsUrl = (url: string, token?: string) => {
|
|
||||||
if (!url) return url;
|
|
||||||
|
|
||||||
// 1. 统一使用 https
|
|
||||||
// 2. 将 /150 (缩略图) 强制改为 /0 (原图)
|
|
||||||
let fixedUrl = url.replace('http://', 'https://').replace(/\/150($|\?)/, '/0$1');
|
|
||||||
|
|
||||||
if (!token || fixedUrl.includes('token=')) return fixedUrl;
|
const fixSnsUrl = (url: string, token?: string, isVideo: boolean = false) => {
|
||||||
|
if (!url) return url
|
||||||
|
|
||||||
const connector = fixedUrl.includes('?') ? '&' : '?';
|
let fixedUrl = url.replace('http://', 'https://')
|
||||||
return `${fixedUrl}${connector}token=${token}&idx=1`;
|
|
||||||
};
|
// 只有非视频(即图片)才需要处理 /150 变 /0
|
||||||
|
if (!isVideo) {
|
||||||
|
fixedUrl = fixedUrl.replace(/\/150($|\?)/, '/0$1')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!token || fixedUrl.includes('token=')) return fixedUrl
|
||||||
|
|
||||||
|
// 根据用户要求,视频链接组合方式为: BASE_URL + "?" + "token=" + token + "&idx=1" + 原有参数
|
||||||
|
if (isVideo) {
|
||||||
|
const urlParts = fixedUrl.split('?')
|
||||||
|
const baseUrl = urlParts[0]
|
||||||
|
const existingParams = urlParts[1] ? `&${urlParts[1]}` : ''
|
||||||
|
return `${baseUrl}?token=${token}&idx=1${existingParams}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const connector = fixedUrl.includes('?') ? '&' : '?'
|
||||||
|
return `${fixedUrl}${connector}token=${token}&idx=1`
|
||||||
|
}
|
||||||
|
|
||||||
|
const detectImageMime = (buf: Buffer, fallback: string = 'image/jpeg') => {
|
||||||
|
if (!buf || buf.length < 4) return fallback
|
||||||
|
|
||||||
|
// JPEG
|
||||||
|
if (buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) return 'image/jpeg'
|
||||||
|
|
||||||
|
// PNG
|
||||||
|
if (
|
||||||
|
buf.length >= 8 &&
|
||||||
|
buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47 &&
|
||||||
|
buf[4] === 0x0d && buf[5] === 0x0a && buf[6] === 0x1a && buf[7] === 0x0a
|
||||||
|
) return 'image/png'
|
||||||
|
|
||||||
|
// GIF
|
||||||
|
if (buf.length >= 6) {
|
||||||
|
const sig = buf.subarray(0, 6).toString('ascii')
|
||||||
|
if (sig === 'GIF87a' || sig === 'GIF89a') return 'image/gif'
|
||||||
|
}
|
||||||
|
|
||||||
|
// WebP
|
||||||
|
if (
|
||||||
|
buf.length >= 12 &&
|
||||||
|
buf[0] === 0x52 && buf[1] === 0x49 && buf[2] === 0x46 && buf[3] === 0x46 &&
|
||||||
|
buf[8] === 0x57 && buf[9] === 0x45 && buf[10] === 0x42 && buf[11] === 0x50
|
||||||
|
) return 'image/webp'
|
||||||
|
|
||||||
|
// BMP
|
||||||
|
if (buf[0] === 0x42 && buf[1] === 0x4d) return 'image/bmp'
|
||||||
|
|
||||||
|
// MP4: 00 00 00 18 / 20 / ... + 'ftyp'
|
||||||
|
if (buf.length > 8 && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70) return 'video/mp4'
|
||||||
|
|
||||||
|
// Fallback logic for video
|
||||||
|
if (fallback.includes('video') || fallback.includes('mp4')) return 'video/mp4'
|
||||||
|
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isVideoUrl = (url: string) => {
|
||||||
|
if (!url) return false
|
||||||
|
// 排除 vweixinthumb 域名 (缩略图)
|
||||||
|
if (url.includes('vweixinthumb')) return false
|
||||||
|
return url.includes('snsvideodownload') || url.includes('video') || url.includes('.mp4')
|
||||||
|
}
|
||||||
|
|
||||||
|
import { Isaac64 } from './isaac64'
|
||||||
|
|
||||||
|
const extractVideoKey = (xml: string): string | undefined => {
|
||||||
|
if (!xml) return undefined
|
||||||
|
// 匹配 <enc key="2105122989" ... /> 或 <enc key="2105122989">
|
||||||
|
const match = xml.match(/<enc\s+key="(\d+)"/i)
|
||||||
|
return match ? match[1] : undefined
|
||||||
|
}
|
||||||
|
|
||||||
class SnsService {
|
class SnsService {
|
||||||
|
private configService: ConfigService
|
||||||
private contactCache: ContactCacheService
|
private contactCache: ContactCacheService
|
||||||
|
private imageCache = new Map<string, string>()
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const config = new ConfigService()
|
this.configService = new ConfigService()
|
||||||
this.contactCache = new ContactCacheService(config.get('cachePath') as string)
|
this.contactCache = new ContactCacheService(this.configService.get('cachePath') as string)
|
||||||
|
}
|
||||||
|
|
||||||
|
private getSnsCacheDir(): string {
|
||||||
|
const cachePath = this.configService.getCacheBasePath()
|
||||||
|
const snsCacheDir = join(cachePath, 'sns_cache')
|
||||||
|
if (!existsSync(snsCacheDir)) {
|
||||||
|
mkdirSync(snsCacheDir, { recursive: true })
|
||||||
|
}
|
||||||
|
return snsCacheDir
|
||||||
|
}
|
||||||
|
|
||||||
|
private getCacheFilePath(url: string): string {
|
||||||
|
const hash = crypto.createHash('md5').update(url).digest('hex')
|
||||||
|
const ext = isVideoUrl(url) ? '.mp4' : '.jpg'
|
||||||
|
return join(this.getSnsCacheDir(), `${hash}${ext}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTimeline(limit: number = 20, offset: number = 0, usernames?: string[], keyword?: string, startTime?: number, endTime?: number): Promise<{ success: boolean; timeline?: SnsPost[]; error?: string }> {
|
async getTimeline(limit: number = 20, offset: number = 0, usernames?: string[], keyword?: string, startTime?: number, endTime?: number): Promise<{ success: boolean; timeline?: SnsPost[]; error?: string }> {
|
||||||
|
|
||||||
|
|
||||||
const result = await wcdbService.getSnsTimeline(limit, offset, usernames, keyword, startTime, endTime)
|
const result = await wcdbService.getSnsTimeline(limit, offset, usernames, keyword, startTime, endTime)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (result.success && result.timeline) {
|
if (result.success && result.timeline) {
|
||||||
const enrichedTimeline = result.timeline.map((post: any, index: number) => {
|
const enrichedTimeline = result.timeline.map((post: any) => {
|
||||||
const contact = this.contactCache.get(post.username)
|
const contact = this.contactCache.get(post.username)
|
||||||
|
const isVideoPost = post.type === 15
|
||||||
|
|
||||||
// 修复媒体 URL
|
// 尝试从 rawXml 中提取视频解密密钥 (针对视频号视频)
|
||||||
const fixedMedia = post.media.map((m: any, mIdx: number) => {
|
const videoKey = extractVideoKey(post.rawXml || '')
|
||||||
const base = {
|
|
||||||
url: fixSnsUrl(m.url, m.token),
|
const fixedMedia = (post.media || []).map((m: any) => ({
|
||||||
thumb: fixSnsUrl(m.thumb, m.token),
|
// 如果是视频动态,url 是视频,thumb 是缩略图
|
||||||
md5: m.md5,
|
url: fixSnsUrl(m.url, m.token, isVideoPost),
|
||||||
token: m.token,
|
thumb: fixSnsUrl(m.thumb, m.token, false),
|
||||||
key: m.key,
|
md5: m.md5,
|
||||||
encIdx: m.encIdx || m.enc_idx, // 兼容不同命名
|
token: m.token,
|
||||||
livePhoto: m.livePhoto ? {
|
// 只有在视频动态 (Type 15) 下才尝试将 XML 提取的 videoKey 赋予主媒体
|
||||||
|
// 对于图片或实况照片的静态部分,应保留原始 m.key (由 DLL/DB 提供),避免由于错误的 Isaac64 密钥导致图片解密损坏
|
||||||
|
key: isVideoPost ? (videoKey || m.key) : m.key,
|
||||||
|
encIdx: m.encIdx || m.enc_idx,
|
||||||
|
livePhoto: m.livePhoto
|
||||||
|
? {
|
||||||
...m.livePhoto,
|
...m.livePhoto,
|
||||||
url: fixSnsUrl(m.livePhoto.url, m.livePhoto.token),
|
url: fixSnsUrl(m.livePhoto.url, m.livePhoto.token, true),
|
||||||
thumb: fixSnsUrl(m.livePhoto.thumb, m.livePhoto.token),
|
thumb: fixSnsUrl(m.livePhoto.thumb, m.livePhoto.token, false),
|
||||||
token: m.livePhoto.token,
|
token: m.livePhoto.token,
|
||||||
key: m.livePhoto.key
|
// 实况照片的视频部分优先使用从 XML 提取的 Key
|
||||||
} : undefined
|
key: videoKey || m.livePhoto.key || m.key,
|
||||||
}
|
encIdx: m.livePhoto.encIdx || m.livePhoto.enc_idx
|
||||||
|
|
||||||
// [MOCK] 模拟数据:如果后端没返回 key (说明 DLL 未更新),注入一些 Mock 数据以便前端开发
|
|
||||||
if (!base.key) {
|
|
||||||
base.key = 'mock_key_for_dev'
|
|
||||||
if (!base.token) {
|
|
||||||
base.token = 'mock_token_for_dev'
|
|
||||||
base.url = fixSnsUrl(base.url, base.token)
|
|
||||||
base.thumb = fixSnsUrl(base.thumb, base.token)
|
|
||||||
}
|
}
|
||||||
base.encIdx = '1'
|
: undefined
|
||||||
|
}))
|
||||||
// 强制给第一个帖子的第一张图加 LivePhoto 模拟
|
|
||||||
if (index === 0 && mIdx === 0 && !base.livePhoto) {
|
|
||||||
base.livePhoto = {
|
|
||||||
url: fixSnsUrl('https://tm.sh/d4cb0.mp4', 'mock_live_token'),
|
|
||||||
thumb: base.thumb,
|
|
||||||
token: 'mock_live_token',
|
|
||||||
key: 'mock_live_key'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return base
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...post,
|
...post,
|
||||||
@@ -116,20 +186,15 @@ class SnsService {
|
|||||||
media: fixedMedia
|
media: fixedMedia
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
return { ...result, timeline: enrichedTimeline }
|
return { ...result, timeline: enrichedTimeline }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
async debugResource(url: string): Promise<{ success: boolean; status?: number; headers?: any; error?: string }> {
|
async debugResource(url: string): Promise<{ success: boolean; status?: number; headers?: any; error?: string }> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
try {
|
try {
|
||||||
const { app, net } = require('electron')
|
|
||||||
// Remove mocking 'require' if it causes issues, but here we need 'net' or 'https'
|
|
||||||
// implementing with 'https' for reliability if 'net' is main-process only special
|
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
const urlObj = new URL(url)
|
const urlObj = new URL(url)
|
||||||
|
|
||||||
@@ -138,13 +203,12 @@ class SnsService {
|
|||||||
path: urlObj.pathname + urlObj.search,
|
path: urlObj.pathname + urlObj.search,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x63090719) XWEB/8351",
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x63090719) XWEB/8351',
|
||||||
"Accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
|
||||||
"Accept-Encoding": "gzip, deflate, br",
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
"Accept-Language": "zh-CN,zh;q=0.9",
|
'Accept-Language': 'zh-CN,zh;q=0.9',
|
||||||
"Referer": "https://servicewechat.com/",
|
'Connection': 'keep-alive',
|
||||||
"Connection": "keep-alive",
|
'Range': 'bytes=0-10'
|
||||||
"Range": "bytes=0-10" // Keep our range check
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,17 +218,15 @@ class SnsService {
|
|||||||
status: res.statusCode,
|
status: res.statusCode,
|
||||||
headers: {
|
headers: {
|
||||||
'x-enc': res.headers['x-enc'],
|
'x-enc': res.headers['x-enc'],
|
||||||
|
'x-time': res.headers['x-time'],
|
||||||
'content-length': res.headers['content-length'],
|
'content-length': res.headers['content-length'],
|
||||||
'content-type': res.headers['content-type']
|
'content-type': res.headers['content-type']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
req.destroy() // We only need headers
|
req.destroy()
|
||||||
})
|
|
||||||
|
|
||||||
req.on('error', (e: any) => {
|
|
||||||
resolve({ success: false, error: e.message })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
req.on('error', (e: any) => resolve({ success: false, error: e.message }))
|
||||||
req.end()
|
req.end()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
resolve({ success: false, error: e.message })
|
resolve({ success: false, error: e.message })
|
||||||
@@ -172,14 +234,163 @@ class SnsService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private imageCache = new Map<string, string>()
|
|
||||||
|
|
||||||
async proxyImage(url: string): Promise<{ success: boolean; dataUrl?: string; error?: string }> {
|
|
||||||
// Check cache
|
async proxyImage(url: string, key?: string | number): Promise<{ success: boolean; dataUrl?: string; videoPath?: string; error?: string }> {
|
||||||
if (this.imageCache.has(url)) {
|
if (!url) return { success: false, error: 'url 不能为空' }
|
||||||
return { success: true, dataUrl: this.imageCache.get(url) }
|
const cacheKey = `${url}|${key ?? ''}`
|
||||||
|
|
||||||
|
if (this.imageCache.has(cacheKey)) {
|
||||||
|
return { success: true, dataUrl: this.imageCache.get(cacheKey) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const result = await this.fetchAndDecryptImage(url, key)
|
||||||
|
if (result.success) {
|
||||||
|
// 如果是视频,返回本地文件路径 (需配合 webSecurity: false 或自定义协议)
|
||||||
|
if (result.contentType?.startsWith('video/')) {
|
||||||
|
// Return cachePath directly for video
|
||||||
|
// 注意:fetchAndDecryptImage 需要修改以返回 cachePath
|
||||||
|
return { success: true, videoPath: result.cachePath }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.data && result.contentType) {
|
||||||
|
const dataUrl = `data:${result.contentType};base64,${result.data.toString('base64')}`
|
||||||
|
this.imageCache.set(cacheKey, dataUrl)
|
||||||
|
return { success: true, dataUrl }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { success: false, error: result.error }
|
||||||
|
}
|
||||||
|
|
||||||
|
async downloadImage(url: string, key?: string | number): Promise<{ success: boolean; data?: Buffer; contentType?: string; error?: string }> {
|
||||||
|
return this.fetchAndDecryptImage(url, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
private async fetchAndDecryptImage(url: string, key?: string | number): Promise<{ success: boolean; data?: Buffer; contentType?: string; cachePath?: string; error?: string }> {
|
||||||
|
if (!url) return { success: false, error: 'url 不能为空' }
|
||||||
|
|
||||||
|
const isVideo = isVideoUrl(url)
|
||||||
|
const cachePath = this.getCacheFilePath(url)
|
||||||
|
|
||||||
|
// 1. 尝试从磁盘缓存读取
|
||||||
|
if (existsSync(cachePath)) {
|
||||||
|
try {
|
||||||
|
// 对于视频,不读取整个文件到内存,只确认存在即可
|
||||||
|
if (isVideo) {
|
||||||
|
return { success: true, cachePath, contentType: 'video/mp4' }
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await readFile(cachePath)
|
||||||
|
const contentType = detectImageMime(data)
|
||||||
|
return { success: true, data, contentType, cachePath }
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`[SnsService] 读取缓存失败: ${cachePath}`, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isVideo) {
|
||||||
|
// 视频专用下载逻辑 (下载 -> 解密 -> 缓存)
|
||||||
|
return new Promise(async (resolve) => {
|
||||||
|
const tmpPath = join(require('os').tmpdir(), `sns_video_${Date.now()}_${Math.random().toString(36).slice(2)}.enc`)
|
||||||
|
console.log(`[SnsService] 开始下载视频到临时文件: ${tmpPath}`)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const https = require('https')
|
||||||
|
const urlObj = new URL(url)
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
const fileStream = fs.createWriteStream(tmpPath)
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
hostname: urlObj.hostname,
|
||||||
|
path: urlObj.pathname + urlObj.search,
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'MicroMessenger Client',
|
||||||
|
'Accept': '*/*',
|
||||||
|
// 'Accept-Encoding': 'gzip, deflate, br', // 视频流通常不压缩,去掉以免 stream 处理复杂
|
||||||
|
'Connection': 'keep-alive'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const req = https.request(options, (res: any) => {
|
||||||
|
if (res.statusCode !== 200 && res.statusCode !== 206) {
|
||||||
|
fileStream.close()
|
||||||
|
fs.unlink(tmpPath, () => { }) // 删除临时文件
|
||||||
|
resolve({ success: false, error: `HTTP ${res.statusCode}` })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res.pipe(fileStream)
|
||||||
|
|
||||||
|
fileStream.on('finish', async () => {
|
||||||
|
fileStream.close()
|
||||||
|
console.log(`[SnsService] 视频下载完成,开始解密... Key: ${key}`)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const encryptedBuffer = await readFile(tmpPath)
|
||||||
|
const raw = encryptedBuffer // 引用,方便后续操作
|
||||||
|
|
||||||
|
|
||||||
|
if (key && String(key).trim().length > 0) {
|
||||||
|
try {
|
||||||
|
console.log(`[SnsService] 使用 WASM Isaac64 解密视频... Key: ${key}`)
|
||||||
|
const wasmService = WasmService.getInstance()
|
||||||
|
// 只需要前 128KB (131072 bytes) 用于解密头部
|
||||||
|
const keystream = await wasmService.getKeystream(String(key), 131072)
|
||||||
|
|
||||||
|
const decryptLen = Math.min(keystream.length, raw.length)
|
||||||
|
|
||||||
|
// XOR 解密
|
||||||
|
for (let i = 0; i < decryptLen; i++) {
|
||||||
|
raw[i] ^= keystream[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证 MP4 签名 ('ftyp' at offset 4)
|
||||||
|
const ftyp = raw.subarray(4, 8).toString('ascii')
|
||||||
|
if (ftyp === 'ftyp') {
|
||||||
|
console.log(`[SnsService] 视频解密成功: ${url}`)
|
||||||
|
} else {
|
||||||
|
console.warn(`[SnsService] 视频解密可能失败: ${url}, 未找到 ftyp 签名: ${ftyp}`)
|
||||||
|
// 打印前 32 字节用于调试
|
||||||
|
console.warn(`[SnsService] Decrypted Header (first 32 bytes): ${raw.subarray(0, 32).toString('hex')}`)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`[SnsService] 视频解密出错: ${err}`)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn(`[SnsService] 未提供 Key,跳过解密,直接保存`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 写入最终缓存 (覆盖)
|
||||||
|
await writeFile(cachePath, raw)
|
||||||
|
console.log(`[SnsService] 视频已保存到缓存: ${cachePath}`)
|
||||||
|
|
||||||
|
// 删除临时文件
|
||||||
|
try { await import('fs/promises').then(fs => fs.unlink(tmpPath)) } catch (e) { }
|
||||||
|
|
||||||
|
resolve({ success: true, data: raw, contentType: 'video/mp4', cachePath })
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error(`[SnsService] 视频处理失败:`, e)
|
||||||
|
resolve({ success: false, error: e.message })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
req.on('error', (e: any) => {
|
||||||
|
fs.unlink(tmpPath, () => { })
|
||||||
|
resolve({ success: false, error: e.message })
|
||||||
|
})
|
||||||
|
|
||||||
|
req.end()
|
||||||
|
|
||||||
|
} catch (e: any) {
|
||||||
|
resolve({ success: false, error: e.message })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 图片逻辑 (保持流式处理)
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
try {
|
try {
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
@@ -191,17 +402,16 @@ class SnsService {
|
|||||||
path: urlObj.pathname + urlObj.search,
|
path: urlObj.pathname + urlObj.search,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x63090719) XWEB/8351",
|
'User-Agent': 'MicroMessenger Client',
|
||||||
"Accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
'Accept': '*/*',
|
||||||
"Accept-Encoding": "gzip, deflate, br",
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
"Accept-Language": "zh-CN,zh;q=0.9",
|
'Accept-Language': 'zh-CN,zh;q=0.9',
|
||||||
"Referer": "https://servicewechat.com/",
|
'Connection': 'keep-alive'
|
||||||
"Connection": "keep-alive"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const req = https.request(options, (res: any) => {
|
const req = https.request(options, (res: any) => {
|
||||||
if (res.statusCode !== 200) {
|
if (res.statusCode !== 200 && res.statusCode !== 206) {
|
||||||
resolve({ success: false, error: `HTTP ${res.statusCode}` })
|
resolve({ success: false, error: `HTTP ${res.statusCode}` })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -209,37 +419,39 @@ class SnsService {
|
|||||||
const chunks: Buffer[] = []
|
const chunks: Buffer[] = []
|
||||||
let stream = res
|
let stream = res
|
||||||
|
|
||||||
// Handle gzip compression
|
|
||||||
const encoding = res.headers['content-encoding']
|
const encoding = res.headers['content-encoding']
|
||||||
if (encoding === 'gzip') {
|
if (encoding === 'gzip') stream = res.pipe(zlib.createGunzip())
|
||||||
stream = res.pipe(zlib.createGunzip())
|
else if (encoding === 'deflate') stream = res.pipe(zlib.createInflate())
|
||||||
} else if (encoding === 'deflate') {
|
else if (encoding === 'br') stream = res.pipe(zlib.createBrotliDecompress())
|
||||||
stream = res.pipe(zlib.createInflate())
|
|
||||||
} else if (encoding === 'br') {
|
|
||||||
stream = res.pipe(zlib.createBrotliDecompress())
|
|
||||||
}
|
|
||||||
|
|
||||||
stream.on('data', (chunk: Buffer) => chunks.push(chunk))
|
stream.on('data', (chunk: Buffer) => chunks.push(chunk))
|
||||||
stream.on('end', () => {
|
stream.on('end', async () => {
|
||||||
const buffer = Buffer.concat(chunks)
|
const raw = Buffer.concat(chunks)
|
||||||
const contentType = res.headers['content-type'] || 'image/jpeg'
|
const xEnc = String(res.headers['x-enc'] || '').trim()
|
||||||
const base64 = buffer.toString('base64')
|
|
||||||
const dataUrl = `data:${contentType};base64,${base64}`
|
|
||||||
|
|
||||||
// Cache
|
let decoded = raw
|
||||||
this.imageCache.set(url, dataUrl)
|
|
||||||
|
|
||||||
resolve({ success: true, dataUrl })
|
// 图片逻辑
|
||||||
})
|
const shouldDecrypt = (xEnc === '1' || !!key) && key !== undefined && key !== null && String(key).trim().length > 0
|
||||||
stream.on('error', (e: any) => {
|
if (shouldDecrypt) {
|
||||||
resolve({ success: false, error: e.message })
|
const decrypted = await wcdbService.decryptSnsImage(raw, String(key))
|
||||||
|
decoded = Buffer.from(decrypted)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 写入磁盘缓存
|
||||||
|
try {
|
||||||
|
await writeFile(cachePath, decoded)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`[SnsService] 写入缓存失败: ${cachePath}`, e)
|
||||||
|
}
|
||||||
|
|
||||||
|
const contentType = detectImageMime(decoded, (res.headers['content-type'] || 'image/jpeg') as string)
|
||||||
|
resolve({ success: true, data: decoded, contentType, cachePath })
|
||||||
})
|
})
|
||||||
|
stream.on('error', (e: any) => resolve({ success: false, error: e.message }))
|
||||||
})
|
})
|
||||||
|
|
||||||
req.on('error', (e: any) => {
|
req.on('error', (e: any) => resolve({ success: false, error: e.message }))
|
||||||
resolve({ success: false, error: e.message })
|
|
||||||
})
|
|
||||||
|
|
||||||
req.end()
|
req.end()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
resolve({ success: false, error: e.message })
|
resolve({ success: false, error: e.message })
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class VideoService {
|
|||||||
* 获取缓存目录(解密后的数据库存放位置)
|
* 获取缓存目录(解密后的数据库存放位置)
|
||||||
*/
|
*/
|
||||||
private getCachePath(): string {
|
private getCachePath(): string {
|
||||||
return this.configService.get('cachePath') || ''
|
return this.configService.getCacheBasePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
175
electron/services/wasmService.ts
Normal file
175
electron/services/wasmService.ts
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import vm from 'vm';
|
||||||
|
|
||||||
|
let app: any;
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
app = require('electron').app;
|
||||||
|
} catch (e) {
|
||||||
|
app = { isPackaged: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
// This service handles the loading and execution of the WeChat WASM module
|
||||||
|
// to generate the correct Isaac64 keystream for video decryption.
|
||||||
|
export class WasmService {
|
||||||
|
private static instance: WasmService;
|
||||||
|
private module: any = null;
|
||||||
|
private wasmLoaded = false;
|
||||||
|
private initPromise: Promise<void> | null = null;
|
||||||
|
private capturedKeystream: Uint8Array | null = null;
|
||||||
|
|
||||||
|
private constructor() { }
|
||||||
|
|
||||||
|
public static getInstance(): WasmService {
|
||||||
|
if (!WasmService.instance) {
|
||||||
|
WasmService.instance = new WasmService();
|
||||||
|
}
|
||||||
|
return WasmService.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async init(): Promise<void> {
|
||||||
|
if (this.wasmLoaded) return;
|
||||||
|
if (this.initPromise) return this.initPromise;
|
||||||
|
|
||||||
|
this.initPromise = new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
// For dev, files are in electron/assets/wasm
|
||||||
|
// __dirname in dev (from dist-electron) is .../dist-electron
|
||||||
|
// So we need to go up one level and then into electron/assets/wasm
|
||||||
|
const isDev = !app.isPackaged;
|
||||||
|
const basePath = isDev
|
||||||
|
? path.join(__dirname, '../electron/assets/wasm')
|
||||||
|
: path.join(process.resourcesPath, 'assets/wasm'); // Adjust as needed for production build
|
||||||
|
|
||||||
|
const wasmPath = path.join(basePath, 'wasm_video_decode.wasm');
|
||||||
|
const jsPath = path.join(basePath, 'wasm_video_decode.js');
|
||||||
|
|
||||||
|
console.log('[WasmService] Loading WASM from:', wasmPath);
|
||||||
|
|
||||||
|
if (!fs.existsSync(wasmPath) || !fs.existsSync(jsPath)) {
|
||||||
|
throw new Error(`WASM files not found at ${basePath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const wasmBinary = fs.readFileSync(wasmPath);
|
||||||
|
|
||||||
|
// Emulate Emscripten environment
|
||||||
|
// We must use 'any' for global mocking
|
||||||
|
const mockGlobal: any = {
|
||||||
|
console: console,
|
||||||
|
Buffer: Buffer,
|
||||||
|
Uint8Array: Uint8Array,
|
||||||
|
Int8Array: Int8Array,
|
||||||
|
Uint16Array: Uint16Array,
|
||||||
|
Int16Array: Int16Array,
|
||||||
|
Uint32Array: Uint32Array,
|
||||||
|
Int32Array: Int32Array,
|
||||||
|
Float32Array: Float32Array,
|
||||||
|
Float64Array: Float64Array,
|
||||||
|
BigInt64Array: BigInt64Array,
|
||||||
|
BigUint64Array: BigUint64Array,
|
||||||
|
Array: Array,
|
||||||
|
Object: Object,
|
||||||
|
Function: Function,
|
||||||
|
String: String,
|
||||||
|
Number: Number,
|
||||||
|
Boolean: Boolean,
|
||||||
|
Error: Error,
|
||||||
|
Promise: Promise,
|
||||||
|
require: require,
|
||||||
|
process: process,
|
||||||
|
setTimeout: setTimeout,
|
||||||
|
clearTimeout: clearTimeout,
|
||||||
|
setInterval: setInterval,
|
||||||
|
clearInterval: clearInterval,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define Module
|
||||||
|
mockGlobal.Module = {
|
||||||
|
onRuntimeInitialized: () => {
|
||||||
|
console.log("[WasmService] WASM Runtime Initialized");
|
||||||
|
this.wasmLoaded = true;
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
wasmBinary: wasmBinary,
|
||||||
|
print: (text: string) => console.log('[WASM stdout]', text),
|
||||||
|
printErr: (text: string) => console.error('[WASM stderr]', text)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define necessary globals for Emscripten loader
|
||||||
|
mockGlobal.self = mockGlobal;
|
||||||
|
mockGlobal.self.location = { href: jsPath };
|
||||||
|
mockGlobal.WorkerGlobalScope = function () { };
|
||||||
|
mockGlobal.VTS_WASM_URL = `file://${wasmPath}`; // Needs a URL, file protocol works in Node context for our mock?
|
||||||
|
|
||||||
|
// Define the callback function that WASM calls to return data
|
||||||
|
// The WASM module calls `wasm_isaac_generate(ptr, size)`
|
||||||
|
mockGlobal.wasm_isaac_generate = (ptr: number, size: number) => {
|
||||||
|
// console.log(`[WasmService] wasm_isaac_generate called: ptr=${ptr}, size=${size}`);
|
||||||
|
const buffer = new Uint8Array(mockGlobal.Module.HEAPU8.buffer, ptr, size);
|
||||||
|
// Copy the data because WASM memory might change or be invalidated
|
||||||
|
this.capturedKeystream = new Uint8Array(buffer);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Execute the loader script in the context
|
||||||
|
const jsContent = fs.readFileSync(jsPath, 'utf8');
|
||||||
|
const script = new vm.Script(jsContent, { filename: jsPath });
|
||||||
|
|
||||||
|
// create context
|
||||||
|
const context = vm.createContext(mockGlobal);
|
||||||
|
script.runInContext(context);
|
||||||
|
|
||||||
|
// Store reference to module
|
||||||
|
this.module = mockGlobal.Module;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[WasmService] Failed to initialize WASM:', error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.initPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getKeystream(key: string, size: number = 131072): Promise<Buffer> {
|
||||||
|
await this.init();
|
||||||
|
|
||||||
|
if (!this.module || !this.module.WxIsaac64) {
|
||||||
|
// Fallback check for asm.WxIsaac64 logic if needed, but debug showed it on Module
|
||||||
|
if (this.module.asm && this.module.asm.WxIsaac64) {
|
||||||
|
this.module.WxIsaac64 = this.module.asm.WxIsaac64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.module.WxIsaac64) {
|
||||||
|
throw new Error('[WasmService] WxIsaac64 not found in WASM module');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.capturedKeystream = null;
|
||||||
|
const isaac = new this.module.WxIsaac64(key);
|
||||||
|
isaac.generate(size); // This triggers the global.wasm_isaac_generate callback
|
||||||
|
|
||||||
|
// Cleanup if possible? isaac.delete()?
|
||||||
|
// In worker code: p.decryptor.delete()
|
||||||
|
if (isaac.delete) {
|
||||||
|
isaac.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.capturedKeystream) {
|
||||||
|
// The worker_release.js logic does:
|
||||||
|
// p.decryptor_array.set(r.reverse())
|
||||||
|
// So the actual keystream is the REVERSE of what is passed to the callback.
|
||||||
|
const reversed = new Uint8Array(this.capturedKeystream);
|
||||||
|
reversed.reverse();
|
||||||
|
return Buffer.from(reversed);
|
||||||
|
} else {
|
||||||
|
throw new Error('[WasmService] Failed to capture keystream (callback not called)');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[WasmService] Error generating keystream:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -64,7 +64,9 @@ export class WcdbCore {
|
|||||||
private wcdbVerifyUser: any = null
|
private wcdbVerifyUser: any = null
|
||||||
private wcdbStartMonitorPipe: any = null
|
private wcdbStartMonitorPipe: any = null
|
||||||
private wcdbStopMonitorPipe: any = null
|
private wcdbStopMonitorPipe: any = null
|
||||||
|
|
||||||
private monitorPipeClient: any = null
|
private monitorPipeClient: any = null
|
||||||
|
private wcdbDecryptSnsImage: any = null
|
||||||
|
|
||||||
private avatarUrlCache: Map<string, { url?: string; updatedAt: number }> = new Map()
|
private avatarUrlCache: Map<string, { url?: string; updatedAt: number }> = new Map()
|
||||||
private readonly avatarCacheTtlMs = 10 * 60 * 1000
|
private readonly avatarCacheTtlMs = 10 * 60 * 1000
|
||||||
@@ -137,11 +139,48 @@ export class WcdbCore {
|
|||||||
this.writeLog('Monitor started via named pipe IPC')
|
this.writeLog('Monitor started via named pipe IPC')
|
||||||
return true
|
return true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('startMonitor failed:', e)
|
console.error('打开数据库异常:', e)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密朋友圈图片
|
||||||
|
*/
|
||||||
|
async decryptSnsImage(encryptedData: Buffer, key: string): Promise<Buffer> {
|
||||||
|
if (!this.initialized) {
|
||||||
|
const initOk = await this.initialize()
|
||||||
|
if (!initOk) return encryptedData
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.wcdbDecryptSnsImage) return encryptedData
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!this.wcdbDecryptSnsImage) {
|
||||||
|
console.error('[WCDB] wcdbDecryptSnsImage func is null')
|
||||||
|
return encryptedData
|
||||||
|
}
|
||||||
|
|
||||||
|
const outPtr = [null as any]
|
||||||
|
// Koffi pass Buffer as char* pointer
|
||||||
|
const result = this.wcdbDecryptSnsImage(encryptedData, encryptedData.length, key, outPtr)
|
||||||
|
|
||||||
|
if (result === 0 && outPtr[0]) {
|
||||||
|
const hex = this.decodeJsonPtr(outPtr[0])
|
||||||
|
if (hex) {
|
||||||
|
return Buffer.from(hex, 'hex')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error(`[WCDB] Decrypt SNS image failed with code: ${result}`)
|
||||||
|
// 主动获取 DLL 内部日志以诊断问题
|
||||||
|
await this.printLogs(true)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('解密图片失败:', e)
|
||||||
|
}
|
||||||
|
return encryptedData
|
||||||
|
}
|
||||||
|
|
||||||
stopMonitor(): void {
|
stopMonitor(): void {
|
||||||
if (this.monitorPipeClient) {
|
if (this.monitorPipeClient) {
|
||||||
this.monitorPipeClient.destroy()
|
this.monitorPipeClient.destroy()
|
||||||
@@ -563,6 +602,13 @@ export class WcdbCore {
|
|||||||
this.wcdbVerifyUser = null
|
this.wcdbVerifyUser = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wcdb_status wcdb_decrypt_sns_image(const char* encrypted_data, int32_t data_len, const char* key, char** out_hex)
|
||||||
|
try {
|
||||||
|
this.wcdbDecryptSnsImage = this.lib.func('int32 wcdb_decrypt_sns_image(const char* data, int32 len, const char* key, _Out_ void** outHex)')
|
||||||
|
} catch {
|
||||||
|
this.wcdbDecryptSnsImage = null
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化
|
// 初始化
|
||||||
const initResult = this.wcdbInit()
|
const initResult = this.wcdbInit()
|
||||||
if (initResult !== 0) {
|
if (initResult !== 0) {
|
||||||
|
|||||||
@@ -431,6 +431,13 @@ export class WcdbService {
|
|||||||
return this.callWorker('verifyUser', { message, hwnd })
|
return this.callWorker('verifyUser', { message, hwnd })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密朋友圈图片
|
||||||
|
*/
|
||||||
|
async decryptSnsImage(encryptedData: Buffer, key: string): Promise<Buffer> {
|
||||||
|
return this.callWorker<Buffer>('decryptSnsImage', { encryptedData, key })
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const wcdbService = new WcdbService()
|
export const wcdbService = new WcdbService()
|
||||||
|
|||||||
@@ -150,6 +150,9 @@ if (parentPort) {
|
|||||||
case 'verifyUser':
|
case 'verifyUser':
|
||||||
result = await core.verifyUser(payload.message, payload.hwnd)
|
result = await core.verifyUser(payload.message, payload.hwnd)
|
||||||
break
|
break
|
||||||
|
case 'decryptSnsImage':
|
||||||
|
result = await core.decryptSnsImage(payload.encryptedData, payload.key)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
result = { success: false, error: `Unknown method: ${type}` }
|
result = { success: false, error: `Unknown method: ${type}` }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,12 +76,10 @@ export async function showNotification(data: any) {
|
|||||||
const isInList = filterList.includes(sessionId)
|
const isInList = filterList.includes(sessionId)
|
||||||
if (filterMode === 'whitelist' && !isInList) {
|
if (filterMode === 'whitelist' && !isInList) {
|
||||||
// 白名单模式:不在列表中则不显示
|
// 白名单模式:不在列表中则不显示
|
||||||
console.log('[NotificationWindow] Filtered by whitelist:', sessionId)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (filterMode === 'blacklist' && isInList) {
|
if (filterMode === 'blacklist' && isInList) {
|
||||||
// 黑名单模式:在列表中则不显示
|
// 黑名单模式:在列表中则不显示
|
||||||
console.log('[NotificationWindow] Filtered by blacklist:', sessionId)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -20,6 +20,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preview-content {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: fit-content;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
.image-preview-close {
|
.image-preview-close {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 40px;
|
bottom: 40px;
|
||||||
@@ -44,3 +53,38 @@
|
|||||||
transform: translateX(-50%) scale(1.1);
|
transform: translateX(-50%) scale(1.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.live-photo-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 15px;
|
||||||
|
right: 15px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
border-radius: 16px;
|
||||||
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
color: #fff;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
cursor: pointer;
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
transition: all 0.2s;
|
||||||
|
z-index: 10000;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
border-color: rgba(255, 255, 255, 0.4);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background: var(--accent-color, #007aff);
|
||||||
|
border-color: transparent;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,36 +1,41 @@
|
|||||||
import React, { useState, useRef, useCallback, useEffect } from 'react'
|
import React, { useState, useRef, useCallback, useEffect } from 'react'
|
||||||
import { X } from 'lucide-react'
|
import { X } from 'lucide-react'
|
||||||
|
import { LivePhotoIcon } from './LivePhotoIcon'
|
||||||
import { createPortal } from 'react-dom'
|
import { createPortal } from 'react-dom'
|
||||||
import './ImagePreview.scss'
|
import './ImagePreview.scss'
|
||||||
|
|
||||||
interface ImagePreviewProps {
|
interface ImagePreviewProps {
|
||||||
src: string
|
src: string
|
||||||
|
isVideo?: boolean
|
||||||
|
liveVideoPath?: string
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ImagePreview: React.FC<ImagePreviewProps> = ({ src, onClose }) => {
|
export const ImagePreview: React.FC<ImagePreviewProps> = ({ src, isVideo, liveVideoPath, onClose }) => {
|
||||||
const [scale, setScale] = useState(1)
|
const [scale, setScale] = useState(1)
|
||||||
const [position, setPosition] = useState({ x: 0, y: 0 })
|
const [position, setPosition] = useState({ x: 0, y: 0 })
|
||||||
const [isDragging, setIsDragging] = useState(false)
|
const [isDragging, setIsDragging] = useState(false)
|
||||||
|
const [showLive, setShowLive] = useState(false)
|
||||||
const dragStart = useRef({ x: 0, y: 0 })
|
const dragStart = useRef({ x: 0, y: 0 })
|
||||||
const positionStart = useRef({ x: 0, y: 0 })
|
const positionStart = useRef({ x: 0, y: 0 })
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
// 滚轮缩放
|
// 滚轮缩放
|
||||||
const handleWheel = useCallback((e: React.WheelEvent) => {
|
const handleWheel = useCallback((e: React.WheelEvent) => {
|
||||||
|
if (showLive) return // 播放实况时禁止缩放? 或者支持缩放? 暂定禁止以简化
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const delta = e.deltaY > 0 ? 0.9 : 1.1
|
const delta = e.deltaY > 0 ? 0.9 : 1.1
|
||||||
setScale(prev => Math.min(Math.max(prev * delta, 0.5), 5))
|
setScale(prev => Math.min(Math.max(prev * delta, 0.5), 5))
|
||||||
}, [])
|
}, [showLive])
|
||||||
|
|
||||||
// 开始拖动
|
// 开始拖动
|
||||||
const handleMouseDown = useCallback((e: React.MouseEvent) => {
|
const handleMouseDown = useCallback((e: React.MouseEvent) => {
|
||||||
if (scale <= 1) return
|
if (showLive || scale <= 1) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setIsDragging(true)
|
setIsDragging(true)
|
||||||
dragStart.current = { x: e.clientX, y: e.clientY }
|
dragStart.current = { x: e.clientX, y: e.clientY }
|
||||||
positionStart.current = { ...position }
|
positionStart.current = { ...position }
|
||||||
}, [scale, position])
|
}, [scale, position, showLive])
|
||||||
|
|
||||||
// 拖动中
|
// 拖动中
|
||||||
const handleMouseMove = useCallback((e: React.MouseEvent) => {
|
const handleMouseMove = useCallback((e: React.MouseEvent) => {
|
||||||
@@ -79,19 +84,62 @@ export const ImagePreview: React.FC<ImagePreviewProps> = ({ src, onClose }) => {
|
|||||||
onMouseUp={handleMouseUp}
|
onMouseUp={handleMouseUp}
|
||||||
onMouseLeave={handleMouseUp}
|
onMouseLeave={handleMouseUp}
|
||||||
>
|
>
|
||||||
<img
|
<div
|
||||||
src={src}
|
className="preview-content"
|
||||||
alt="图片预览"
|
|
||||||
className={`preview-image ${isDragging ? 'dragging' : ''}`}
|
|
||||||
style={{
|
style={{
|
||||||
transform: `translate(${position.x}px, ${position.y}px) scale(${scale})`,
|
position: 'relative',
|
||||||
cursor: scale > 1 ? (isDragging ? 'grabbing' : 'grab') : 'default'
|
transform: `translate(${position.x}px, ${position.y}px)`,
|
||||||
|
width: 'fit-content',
|
||||||
|
height: 'fit-content'
|
||||||
}}
|
}}
|
||||||
onWheel={handleWheel}
|
onClick={(e) => e.stopPropagation()}
|
||||||
onMouseDown={handleMouseDown}
|
>
|
||||||
onDoubleClick={handleDoubleClick}
|
{(isVideo || showLive) ? (
|
||||||
draggable={false}
|
<video
|
||||||
/>
|
src={showLive ? liveVideoPath : src}
|
||||||
|
controls={!showLive}
|
||||||
|
autoPlay
|
||||||
|
loop={showLive}
|
||||||
|
className="preview-image"
|
||||||
|
style={{
|
||||||
|
transform: `scale(${scale})`,
|
||||||
|
maxHeight: '90vh',
|
||||||
|
maxWidth: '90vw'
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<img
|
||||||
|
src={src}
|
||||||
|
alt="图片预览"
|
||||||
|
className={`preview-image ${isDragging ? 'dragging' : ''}`}
|
||||||
|
style={{
|
||||||
|
transform: `scale(${scale})`,
|
||||||
|
maxHeight: '90vh',
|
||||||
|
maxWidth: '90vw',
|
||||||
|
cursor: scale > 1 ? (isDragging ? 'grabbing' : 'grab') : 'default'
|
||||||
|
}}
|
||||||
|
onWheel={handleWheel}
|
||||||
|
onMouseDown={handleMouseDown}
|
||||||
|
onDoubleClick={handleDoubleClick}
|
||||||
|
draggable={false}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{liveVideoPath && !isVideo && (
|
||||||
|
<button
|
||||||
|
className={`live-photo-btn ${showLive ? 'active' : ''}`}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
setShowLive(!showLive)
|
||||||
|
}}
|
||||||
|
title={showLive ? "显示照片" : "播放实况"}
|
||||||
|
>
|
||||||
|
<LivePhotoIcon size={20} />
|
||||||
|
<span>实况</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<button className="image-preview-close" onClick={onClose}>
|
<button className="image-preview-close" onClick={onClose}>
|
||||||
<X size={20} />
|
<X size={20} />
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ function SettingsPage() {
|
|||||||
const exportExcelColumnsDropdownRef = useRef<HTMLDivElement>(null)
|
const exportExcelColumnsDropdownRef = useRef<HTMLDivElement>(null)
|
||||||
const exportConcurrencyDropdownRef = useRef<HTMLDivElement>(null)
|
const exportConcurrencyDropdownRef = useRef<HTMLDivElement>(null)
|
||||||
const [cachePath, setCachePath] = useState('')
|
const [cachePath, setCachePath] = useState('')
|
||||||
|
const [weixinDllPath, setWeixinDllPath] = useState('')
|
||||||
const [logEnabled, setLogEnabled] = useState(false)
|
const [logEnabled, setLogEnabled] = useState(false)
|
||||||
const [whisperModelName, setWhisperModelName] = useState('base')
|
const [whisperModelName, setWhisperModelName] = useState('base')
|
||||||
const [whisperModelDir, setWhisperModelDir] = useState('')
|
const [whisperModelDir, setWhisperModelDir] = useState('')
|
||||||
@@ -249,6 +250,7 @@ function SettingsPage() {
|
|||||||
const savedPath = await configService.getDbPath()
|
const savedPath = await configService.getDbPath()
|
||||||
const savedWxid = await configService.getMyWxid()
|
const savedWxid = await configService.getMyWxid()
|
||||||
const savedCachePath = await configService.getCachePath()
|
const savedCachePath = await configService.getCachePath()
|
||||||
|
const savedWeixinDllPath = await configService.getWeixinDllPath()
|
||||||
const savedExportPath = await configService.getExportPath()
|
const savedExportPath = await configService.getExportPath()
|
||||||
const savedLogEnabled = await configService.getLogEnabled()
|
const savedLogEnabled = await configService.getLogEnabled()
|
||||||
const savedImageXorKey = await configService.getImageXorKey()
|
const savedImageXorKey = await configService.getImageXorKey()
|
||||||
@@ -277,6 +279,7 @@ function SettingsPage() {
|
|||||||
if (savedPath) setDbPath(savedPath)
|
if (savedPath) setDbPath(savedPath)
|
||||||
if (savedWxid) setWxid(savedWxid)
|
if (savedWxid) setWxid(savedWxid)
|
||||||
if (savedCachePath) setCachePath(savedCachePath)
|
if (savedCachePath) setCachePath(savedCachePath)
|
||||||
|
if (savedWeixinDllPath) setWeixinDllPath(savedWeixinDllPath)
|
||||||
|
|
||||||
const wxidConfig = savedWxid ? await configService.getWxidConfig(savedWxid) : null
|
const wxidConfig = savedWxid ? await configService.getWxidConfig(savedWxid) : null
|
||||||
const decryptKeyToUse = wxidConfig?.decryptKey ?? savedKey ?? ''
|
const decryptKeyToUse = wxidConfig?.decryptKey ?? savedKey ?? ''
|
||||||
@@ -613,6 +616,29 @@ function SettingsPage() {
|
|||||||
await applyWxidSelection(selectedWxid)
|
await applyWxidSelection(selectedWxid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSelectWeixinDllPath = async () => {
|
||||||
|
try {
|
||||||
|
const result = await dialog.openFile({
|
||||||
|
title: '选择 Weixin.dll 文件',
|
||||||
|
properties: ['openFile'],
|
||||||
|
filters: [{ name: 'DLL', extensions: ['dll'] }]
|
||||||
|
})
|
||||||
|
if (!result.canceled && result.filePaths.length > 0) {
|
||||||
|
const selectedPath = result.filePaths[0]
|
||||||
|
setWeixinDllPath(selectedPath)
|
||||||
|
await configService.setWeixinDllPath(selectedPath)
|
||||||
|
showMessage('已选择 Weixin.dll 路径', true)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
showMessage('选择 Weixin.dll 失败', false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleResetWeixinDllPath = async () => {
|
||||||
|
setWeixinDllPath('')
|
||||||
|
await configService.setWeixinDllPath('')
|
||||||
|
showMessage('已清空 Weixin.dll 路径', true)
|
||||||
|
}
|
||||||
const handleSelectCachePath = async () => {
|
const handleSelectCachePath = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await dialog.openFile({ title: '选择缓存目录', properties: ['openDirectory'] })
|
const result = await dialog.openFile({ title: '选择缓存目录', properties: ['openDirectory'] })
|
||||||
@@ -1306,6 +1332,29 @@ function SettingsPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="form-group">
|
||||||
|
<label>Weixin.dll 路径 <span className="optional">(可选)</span></label>
|
||||||
|
<span className="form-hint">用于朋友圈在线图片原生解密,优先使用这里配置的 DLL</span>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="例如: D:\weixindata\Weixin\Weixin.dll"
|
||||||
|
value={weixinDllPath}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value
|
||||||
|
setWeixinDllPath(value)
|
||||||
|
scheduleConfigSave('weixinDllPath', () => configService.setWeixinDllPath(value))
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="btn-row">
|
||||||
|
<button className="btn btn-secondary" onClick={handleSelectWeixinDllPath}>
|
||||||
|
<FolderOpen size={16} /> 浏览选择
|
||||||
|
</button>
|
||||||
|
<button className="btn btn-secondary" onClick={handleResetWeixinDllPath}>
|
||||||
|
清空
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label>账号 wxid</label>
|
<label>账号 wxid</label>
|
||||||
<span className="form-hint">微信账号标识</span>
|
<span className="form-hint">微信账号标识</span>
|
||||||
|
|||||||
@@ -809,6 +809,60 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.video-badge-container {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
z-index: 2;
|
||||||
|
pointer-events: none;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
.video-badge {
|
||||||
|
width: 44px;
|
||||||
|
height: 44px;
|
||||||
|
background: rgba(0, 0, 0, 0.3);
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
border-radius: 50%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: white;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||||
|
transition: all 0.2s;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||||
|
|
||||||
|
svg {
|
||||||
|
fill: white;
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.decrypting-badge {
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
backdrop-filter: blur(8px);
|
||||||
|
padding: 8px 16px;
|
||||||
|
border-radius: 20px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: white;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 500;
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
|
white-space: nowrap;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
||||||
|
|
||||||
|
.spin-icon {
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
.download-btn-overlay {
|
.download-btn-overlay {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
@@ -1207,4 +1261,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -34,47 +34,228 @@ interface SnsPost {
|
|||||||
rawXml?: string // 原始 XML 数据
|
rawXml?: string // 原始 XML 数据
|
||||||
}
|
}
|
||||||
|
|
||||||
const MediaItem = ({ media, onPreview }: { media: any, onPreview: () => void }) => {
|
const MediaItem = ({ media, onPreview }: { media: any; onPreview: (src: string, isVideo?: boolean, liveVideoPath?: string) => void }) => {
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false)
|
||||||
const { url, thumb, livePhoto } = media;
|
const [thumbSrc, setThumbSrc] = useState<string>('') // 缩略图
|
||||||
const isLive = !!livePhoto;
|
const [videoPath, setVideoPath] = useState<string>('') // 视频本地路径
|
||||||
const targetUrl = thumb || url;
|
const [liveVideoPath, setLiveVideoPath] = useState<string>('') // Live Photo 视频路径
|
||||||
|
const [isDecrypting, setIsDecrypting] = useState(false) // 解密状态
|
||||||
|
const { url, thumb, livePhoto } = media
|
||||||
|
const isLive = !!livePhoto
|
||||||
|
const targetUrl = thumb || url // 默认显示缩略图
|
||||||
|
|
||||||
const handleDownload = (e: React.MouseEvent) => {
|
// 判断是否为视频
|
||||||
e.stopPropagation();
|
const isVideo = url && (url.includes('snsvideodownload') || url.includes('.mp4') || url.includes('video')) && !url.includes('vweixinthumb')
|
||||||
|
|
||||||
let downloadUrl = url;
|
useEffect(() => {
|
||||||
let downloadKey = media.key || '';
|
let cancelled = false
|
||||||
|
setError(false)
|
||||||
|
setThumbSrc('')
|
||||||
|
setVideoPath('')
|
||||||
|
setLiveVideoPath('')
|
||||||
|
setIsDecrypting(false)
|
||||||
|
|
||||||
if (isLive && media.livePhoto) {
|
const extractFirstFrame = (videoUrl: string) => {
|
||||||
downloadUrl = media.livePhoto.url;
|
const video = document.createElement('video')
|
||||||
downloadKey = media.livePhoto.key || '';
|
video.crossOrigin = 'anonymous'
|
||||||
|
video.style.display = 'none'
|
||||||
|
video.muted = true
|
||||||
|
video.src = videoUrl
|
||||||
|
video.currentTime = 0.1
|
||||||
|
|
||||||
|
const onLoadedData = () => {
|
||||||
|
if (cancelled) return cleanup()
|
||||||
|
try {
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
canvas.width = video.videoWidth
|
||||||
|
canvas.height = video.videoHeight
|
||||||
|
const ctx = canvas.getContext('2d')
|
||||||
|
if (ctx) {
|
||||||
|
ctx.drawImage(video, 0, 0, canvas.width, canvas.height)
|
||||||
|
const dataUrl = canvas.toDataURL('image/jpeg', 0.8)
|
||||||
|
if (!cancelled) {
|
||||||
|
setThumbSrc(dataUrl)
|
||||||
|
setIsDecrypting(false)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!cancelled) setIsDecrypting(false)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Frame extraction error', e)
|
||||||
|
if (!cancelled) setIsDecrypting(false)
|
||||||
|
} finally {
|
||||||
|
cleanup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onError = () => {
|
||||||
|
if (!cancelled) {
|
||||||
|
setIsDecrypting(false)
|
||||||
|
setThumbSrc(targetUrl) // Fallback
|
||||||
|
}
|
||||||
|
cleanup()
|
||||||
|
}
|
||||||
|
|
||||||
|
const cleanup = () => {
|
||||||
|
video.removeEventListener('seeked', onLoadedData)
|
||||||
|
video.removeEventListener('error', onError)
|
||||||
|
video.remove()
|
||||||
|
}
|
||||||
|
|
||||||
|
video.addEventListener('seeked', onLoadedData)
|
||||||
|
video.addEventListener('error', onError)
|
||||||
|
video.load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 调用后端下载服务
|
const run = async () => {
|
||||||
// window.electronAPI.sns.download(downloadUrl, downloadKey);
|
try {
|
||||||
};
|
if (isVideo) {
|
||||||
|
setIsDecrypting(true)
|
||||||
|
|
||||||
|
const videoResult = await window.electronAPI.sns.proxyImage({
|
||||||
|
url: url,
|
||||||
|
key: media.key
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cancelled) return
|
||||||
|
|
||||||
|
if (videoResult.success && videoResult.videoPath) {
|
||||||
|
const localUrl = videoResult.videoPath.startsWith('file:')
|
||||||
|
? videoResult.videoPath
|
||||||
|
: `file://${videoResult.videoPath.replace(/\\/g, '/')}`
|
||||||
|
setVideoPath(localUrl)
|
||||||
|
extractFirstFrame(localUrl)
|
||||||
|
} else {
|
||||||
|
console.warn('[MediaItem] Video decryption failed:', url, videoResult.error)
|
||||||
|
setIsDecrypting(false)
|
||||||
|
setError(true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const result = await window.electronAPI.sns.proxyImage({
|
||||||
|
url: targetUrl,
|
||||||
|
key: media.key
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cancelled) return
|
||||||
|
if (result.success) {
|
||||||
|
if (result.dataUrl) {
|
||||||
|
setThumbSrc(result.dataUrl)
|
||||||
|
} else if (result.videoPath) {
|
||||||
|
const localUrl = result.videoPath.startsWith('file:')
|
||||||
|
? result.videoPath
|
||||||
|
: `file://${result.videoPath.replace(/\\/g, '/')}`
|
||||||
|
setThumbSrc(localUrl)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('[MediaItem] Image proxy failed:', targetUrl, result.error)
|
||||||
|
setThumbSrc(targetUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLive && livePhoto && livePhoto.url) {
|
||||||
|
window.electronAPI.sns.proxyImage({
|
||||||
|
url: livePhoto.url,
|
||||||
|
key: livePhoto.key || media.key
|
||||||
|
}).then((res: any) => {
|
||||||
|
if (cancelled) return
|
||||||
|
if (res.success && res.videoPath) {
|
||||||
|
const localUrl = res.videoPath.startsWith('file:')
|
||||||
|
? res.videoPath
|
||||||
|
: `file://${res.videoPath.replace(/\\/g, '/')}`
|
||||||
|
setLiveVideoPath(localUrl)
|
||||||
|
console.log('[MediaItem] Live video ready:', localUrl)
|
||||||
|
} else {
|
||||||
|
console.warn('[MediaItem] Live video failed:', res.error)
|
||||||
|
}
|
||||||
|
}).catch((e: any) => console.error('[MediaItem] Live video err:', e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (!cancelled) {
|
||||||
|
console.error('[MediaItem] run error:', err)
|
||||||
|
setError(true)
|
||||||
|
setIsDecrypting(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
|
return () => { cancelled = true }
|
||||||
|
}, [targetUrl, url, media.key, isVideo, isLive, livePhoto])
|
||||||
|
|
||||||
|
const handleDownload = async (e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
try {
|
||||||
|
const result = await window.electronAPI.sns.downloadImage({
|
||||||
|
url: url || targetUrl, // Use original url if available
|
||||||
|
key: media.key
|
||||||
|
})
|
||||||
|
if (!result.success && result.error !== '用户已取消') {
|
||||||
|
alert(`下载失败: ${result.error}`)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Download failed:', error)
|
||||||
|
alert('下载过程中发生错误')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 点击时:如果是视频,应该传视频地址给 Preview?
|
||||||
|
// ImagePreview 目前可能只支持图片。需要检查 ImagePreview 是否支持视频。
|
||||||
|
// 假设 ImagePreview 暂不支持视频播放,我们可以在这里直接点开播放?
|
||||||
|
// 或者,传视频 URL 给 onPreview,让父组件决定/ImagePreview 决定。
|
||||||
|
// 通常做法:传给 ImagePreview,ImagePreview 识别 mp4 后播放。
|
||||||
|
|
||||||
|
// 显示用的图片:始终显示缩略图
|
||||||
|
const displaySrc = thumbSrc || targetUrl
|
||||||
|
|
||||||
|
// 预览用的地址:如果是视频,优先使用本地路径
|
||||||
|
const previewSrc = isVideo ? (videoPath || url) : (thumbSrc || url || targetUrl)
|
||||||
|
|
||||||
|
// 点击处理:解密中禁止点击
|
||||||
|
const handleClick = () => {
|
||||||
|
if (isVideo && isDecrypting) return
|
||||||
|
onPreview(previewSrc, isVideo, liveVideoPath)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`media-item ${error ? 'error' : ''}`} onClick={onPreview}>
|
<div className={`media-item ${error ? 'error' : ''} ${isVideo && isDecrypting ? 'decrypting' : ''}`} onClick={handleClick}>
|
||||||
<img
|
{isVideo && isDecrypting ? (
|
||||||
src={targetUrl}
|
<div className="video-loading-overlay" style={{
|
||||||
alt=""
|
position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column',
|
||||||
referrerPolicy="no-referrer"
|
alignItems: 'center', justifyContent: 'center', background: 'rgba(0,0,0,0.5)', color: '#fff',
|
||||||
loading="lazy"
|
zIndex: 2, backdropFilter: 'blur(4px)'
|
||||||
onError={() => setError(true)}
|
}}>
|
||||||
/>
|
<RefreshCw size={24} className="spin-icon" style={{ marginBottom: 8 }} />
|
||||||
{isLive && (
|
<span style={{ fontSize: 12 }}>解密中...</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<img
|
||||||
|
src={displaySrc}
|
||||||
|
alt=""
|
||||||
|
referrerPolicy="no-referrer"
|
||||||
|
loading="lazy"
|
||||||
|
onError={() => setError(true)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isVideo && !isDecrypting && (
|
||||||
|
<div className="video-badge-container">
|
||||||
|
<div className="video-badge">
|
||||||
|
<Play size={16} className="play-icon" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isLive && !isVideo && (
|
||||||
<div className="live-badge">
|
<div className="live-badge">
|
||||||
<LivePhotoIcon size={16} className="live-icon" />
|
<LivePhotoIcon size={16} className="live-icon" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<button className="download-btn-overlay" onClick={handleDownload} title="下载原图">
|
<button className="download-btn-overlay" onClick={handleDownload} title="Download original">
|
||||||
<Download size={14} />
|
<Download size={14} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
interface Contact {
|
interface Contact {
|
||||||
username: string
|
username: string
|
||||||
@@ -100,7 +281,7 @@ export default function SnsPage() {
|
|||||||
const [contactsLoading, setContactsLoading] = useState(false)
|
const [contactsLoading, setContactsLoading] = useState(false)
|
||||||
const [showJumpDialog, setShowJumpDialog] = useState(false)
|
const [showJumpDialog, setShowJumpDialog] = useState(false)
|
||||||
const [jumpTargetDate, setJumpTargetDate] = useState<Date | undefined>(undefined)
|
const [jumpTargetDate, setJumpTargetDate] = useState<Date | undefined>(undefined)
|
||||||
const [previewImage, setPreviewImage] = useState<string | null>(null)
|
const [previewImage, setPreviewImage] = useState<{ src: string, isVideo?: boolean, liveVideoPath?: string } | null>(null)
|
||||||
const [debugPost, setDebugPost] = useState<SnsPost | null>(null)
|
const [debugPost, setDebugPost] = useState<SnsPost | null>(null)
|
||||||
|
|
||||||
const postsContainerRef = useRef<HTMLDivElement>(null)
|
const postsContainerRef = useRef<HTMLDivElement>(null)
|
||||||
@@ -412,10 +593,6 @@ export default function SnsPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="sns-content-wrapper">
|
<div className="sns-content-wrapper">
|
||||||
<div className="sns-notice-banner">
|
|
||||||
<AlertTriangle size={16} />
|
|
||||||
<span>由于技术限制,当前无法解密显示部分图片与视频等加密资源文件</span>
|
|
||||||
</div>
|
|
||||||
<div className="sns-content custom-scrollbar" onScroll={handleScroll} onWheel={handleWheel} ref={postsContainerRef}>
|
<div className="sns-content custom-scrollbar" onScroll={handleScroll} onWheel={handleWheel} ref={postsContainerRef}>
|
||||||
<div className="posts-list">
|
<div className="posts-list">
|
||||||
{loadingNewer && (
|
{loadingNewer && (
|
||||||
@@ -463,15 +640,10 @@ export default function SnsPage() {
|
|||||||
<div className="post-body">
|
<div className="post-body">
|
||||||
{post.contentDesc && <div className="post-text">{post.contentDesc}</div>}
|
{post.contentDesc && <div className="post-text">{post.contentDesc}</div>}
|
||||||
|
|
||||||
{post.type === 15 ? (
|
{post.media.length > 0 && (
|
||||||
<div className="post-video-placeholder">
|
|
||||||
<Play size={20} />
|
|
||||||
<span>视频动态</span>
|
|
||||||
</div>
|
|
||||||
) : post.media.length > 0 && (
|
|
||||||
<div className={`post-media-grid media-count-${Math.min(post.media.length, 9)}`}>
|
<div className={`post-media-grid media-count-${Math.min(post.media.length, 9)}`}>
|
||||||
{post.media.map((m, idx) => (
|
{post.media.map((m, idx) => (
|
||||||
<MediaItem key={idx} media={m} onPreview={() => setPreviewImage(m.url)} />
|
<MediaItem key={idx} media={m} onPreview={(src, isVideo, liveVideoPath) => setPreviewImage({ src, isVideo, liveVideoPath })} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -644,7 +816,12 @@ export default function SnsPage() {
|
|||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
{previewImage && (
|
{previewImage && (
|
||||||
<ImagePreview src={previewImage} onClose={() => setPreviewImage(null)} />
|
<ImagePreview
|
||||||
|
src={previewImage.src}
|
||||||
|
isVideo={previewImage.isVideo}
|
||||||
|
liveVideoPath={previewImage.liveVideoPath}
|
||||||
|
onClose={() => setPreviewImage(null)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
<JumpToDateDialog
|
<JumpToDateDialog
|
||||||
isOpen={showJumpDialog}
|
isOpen={showJumpDialog}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export const CONFIG_KEYS = {
|
|||||||
LAST_SESSION: 'lastSession',
|
LAST_SESSION: 'lastSession',
|
||||||
WINDOW_BOUNDS: 'windowBounds',
|
WINDOW_BOUNDS: 'windowBounds',
|
||||||
CACHE_PATH: 'cachePath',
|
CACHE_PATH: 'cachePath',
|
||||||
|
WEIXIN_DLL_PATH: 'weixinDllPath',
|
||||||
EXPORT_PATH: 'exportPath',
|
EXPORT_PATH: 'exportPath',
|
||||||
AGREEMENT_ACCEPTED: 'agreementAccepted',
|
AGREEMENT_ACCEPTED: 'agreementAccepted',
|
||||||
LOG_ENABLED: 'logEnabled',
|
LOG_ENABLED: 'logEnabled',
|
||||||
@@ -162,6 +163,17 @@ export async function setCachePath(path: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 获取 Weixin.dll 路径
|
||||||
|
export async function getWeixinDllPath(): Promise<string | null> {
|
||||||
|
const value = await config.get(CONFIG_KEYS.WEIXIN_DLL_PATH)
|
||||||
|
return value as string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置 Weixin.dll 路径
|
||||||
|
export async function setWeixinDllPath(path: string): Promise<void> {
|
||||||
|
await config.set(CONFIG_KEYS.WEIXIN_DLL_PATH, path)
|
||||||
|
}
|
||||||
|
|
||||||
// 获取导出路径
|
// 获取导出路径
|
||||||
export async function getExportPath(): Promise<string | null> {
|
export async function getExportPath(): Promise<string | null> {
|
||||||
const value = await config.get(CONFIG_KEYS.EXPORT_PATH)
|
const value = await config.get(CONFIG_KEYS.EXPORT_PATH)
|
||||||
|
|||||||
2
src/types/electron.d.ts
vendored
2
src/types/electron.d.ts
vendored
@@ -477,7 +477,7 @@ export interface ElectronAPI {
|
|||||||
error?: string
|
error?: string
|
||||||
}>
|
}>
|
||||||
debugResource: (url: string) => Promise<{ success: boolean; status?: number; headers?: any; error?: string }>
|
debugResource: (url: string) => Promise<{ success: boolean; status?: number; headers?: any; error?: string }>
|
||||||
proxyImage: (url: string) => Promise<{ success: boolean; dataUrl?: string; error?: string }>
|
proxyImage: (payload: { url: string; key?: string | number }) => Promise<{ success: boolean; dataUrl?: string; error?: string }>
|
||||||
}
|
}
|
||||||
llama: {
|
llama: {
|
||||||
loadModel: (modelPath: string) => Promise<boolean>
|
loadModel: (modelPath: string) => Promise<boolean>
|
||||||
|
|||||||
Reference in New Issue
Block a user