mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-25 07:16:51 +00:00
@@ -932,8 +932,10 @@ 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)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 私聊克隆
|
// 私聊克隆
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ 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)
|
||||||
},
|
},
|
||||||
|
|
||||||
// Llama AI
|
// Llama AI
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ interface ConfigSchema {
|
|||||||
|
|
||||||
// 缓存相关
|
// 缓存相关
|
||||||
cachePath: string
|
cachePath: string
|
||||||
|
weixinDllPath: string
|
||||||
lastOpenedDb: string
|
lastOpenedDb: string
|
||||||
lastSession: string
|
lastSession: string
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ export class ConfigService {
|
|||||||
imageAesKey: '',
|
imageAesKey: '',
|
||||||
wxidConfigs: {},
|
wxidConfigs: {},
|
||||||
cachePath: '',
|
cachePath: '',
|
||||||
|
weixinDllPath: '',
|
||||||
lastOpenedDb: '',
|
lastOpenedDb: '',
|
||||||
lastSession: '',
|
lastSession: '',
|
||||||
theme: 'system',
|
theme: 'system',
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
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 } from 'fs'
|
||||||
|
import { basename, join } from 'path'
|
||||||
|
|
||||||
export interface SnsLivePhoto {
|
export interface SnsLivePhoto {
|
||||||
url: string
|
url: string
|
||||||
@@ -32,82 +34,88 @@ 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 WEIXIN_DLL_OFFSET = 0x2674280n
|
||||||
|
|
||||||
const fixSnsUrl = (url: string, token?: string) => {
|
const fixSnsUrl = (url: string, token?: string) => {
|
||||||
if (!url) return url;
|
if (!url) return url
|
||||||
|
|
||||||
// 1. 统一使用 https
|
let fixedUrl = url.replace('http://', 'https://').replace(/\/150($|\?)/, '/0$1')
|
||||||
// 2. 将 /150 (缩略图) 强制改为 /0 (原图)
|
if (!token || fixedUrl.includes('token=')) return fixedUrl
|
||||||
let fixedUrl = url.replace('http://', 'https://').replace(/\/150($|\?)/, '/0$1');
|
|
||||||
|
|
||||||
if (!token || fixedUrl.includes('token=')) return fixedUrl;
|
const connector = fixedUrl.includes('?') ? '&' : '?'
|
||||||
|
return `${fixedUrl}${connector}token=${token}&idx=1`
|
||||||
|
}
|
||||||
|
|
||||||
const connector = fixedUrl.includes('?') ? '&' : '?';
|
const detectImageMime = (buf: Buffer, fallback: string = 'image/jpeg') => {
|
||||||
return `${fixedUrl}${connector}token=${token}&idx=1`;
|
if (!buf || buf.length < 4) return fallback
|
||||||
};
|
if (buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff) return 'image/jpeg'
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
if (buf.length >= 6) {
|
||||||
|
const sig = buf.subarray(0, 6).toString('ascii')
|
||||||
|
if (sig === 'GIF87a' || sig === 'GIF89a') return 'image/gif'
|
||||||
|
}
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
if (buf[0] === 0x42 && buf[1] === 0x4d) return 'image/bmp'
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
class SnsService {
|
class SnsService {
|
||||||
|
private configService: ConfigService
|
||||||
private contactCache: ContactCacheService
|
private contactCache: ContactCacheService
|
||||||
|
private imageCache = new Map<string, string>()
|
||||||
|
|
||||||
|
private nativeDecryptInit = false
|
||||||
|
private nativeDecryptReady = false
|
||||||
|
private nativeDecryptError = ''
|
||||||
|
private nativeDecryptDllPath = ''
|
||||||
|
private nativeKoffi: any = null
|
||||||
|
private nativeWeixinLib: any = null
|
||||||
|
private nativeDecryptFn: any = null
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 fixedMedia = (post.media || []).map((m: any) => ({
|
||||||
// 修复媒体 URL
|
url: fixSnsUrl(m.url, m.token),
|
||||||
const fixedMedia = post.media.map((m: any, mIdx: number) => {
|
thumb: fixSnsUrl(m.thumb, m.token),
|
||||||
const base = {
|
md5: m.md5,
|
||||||
url: fixSnsUrl(m.url, m.token),
|
token: m.token,
|
||||||
thumb: fixSnsUrl(m.thumb, m.token),
|
key: m.key,
|
||||||
md5: m.md5,
|
encIdx: m.encIdx || m.enc_idx,
|
||||||
token: m.token,
|
livePhoto: m.livePhoto
|
||||||
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),
|
||||||
thumb: fixSnsUrl(m.livePhoto.thumb, m.livePhoto.token),
|
thumb: fixSnsUrl(m.livePhoto.thumb, m.livePhoto.token),
|
||||||
token: m.livePhoto.token,
|
token: m.livePhoto.token,
|
||||||
key: m.livePhoto.key
|
key: m.livePhoto.key,
|
||||||
} : undefined
|
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 +124,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 +141,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 +156,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,12 +172,131 @@ class SnsService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private imageCache = new Map<string, string>()
|
private parseSnsKey(key?: string | number): bigint | null {
|
||||||
|
if (key === undefined || key === null) return null
|
||||||
|
if (typeof key === 'number') return BigInt(Math.trunc(key))
|
||||||
|
const raw = String(key).trim()
|
||||||
|
if (!raw) return null
|
||||||
|
try {
|
||||||
|
return BigInt(raw)
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private resolveWeixinDllPath(): string | null {
|
||||||
|
const candidates: string[] = []
|
||||||
|
|
||||||
async proxyImage(url: string): Promise<{ success: boolean; dataUrl?: string; error?: string }> {
|
if (process.env.WEFLOW_WEIXIN_DLL) candidates.push(process.env.WEFLOW_WEIXIN_DLL)
|
||||||
// Check cache
|
|
||||||
if (this.imageCache.has(url)) {
|
const configuredPath = String(this.configService.get('weixinDllPath') || '').trim()
|
||||||
return { success: true, dataUrl: this.imageCache.get(url) }
|
if (configuredPath) candidates.push(configuredPath)
|
||||||
|
|
||||||
|
const weixinExe = process.env.WEFLOW_WEIXIN_EXE
|
||||||
|
if (weixinExe) {
|
||||||
|
const dir = weixinExe.replace(/\\Weixin\.exe$/i, '')
|
||||||
|
if (dir && dir !== weixinExe) candidates.push(join(dir, 'Weixin.dll'))
|
||||||
|
}
|
||||||
|
|
||||||
|
const programFiles = process.env.ProgramFiles || 'C:\\Program Files'
|
||||||
|
const localAppData = process.env.LOCALAPPDATA || ''
|
||||||
|
candidates.push(join(programFiles, 'Tencent', 'Weixin', 'Weixin.dll'))
|
||||||
|
if (localAppData) candidates.push(join(localAppData, 'Tencent', 'xwechat', 'Weixin.dll'))
|
||||||
|
|
||||||
|
const seen = new Set<string>()
|
||||||
|
for (const p of candidates) {
|
||||||
|
if (!p) continue
|
||||||
|
const normalized = p.trim()
|
||||||
|
if (!normalized || seen.has(normalized)) continue
|
||||||
|
seen.add(normalized)
|
||||||
|
if (existsSync(normalized)) return normalized
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
private ensureNativeDecryptor(): boolean {
|
||||||
|
const configuredPath = String(this.configService.get('weixinDllPath') || '').trim()
|
||||||
|
if (this.nativeDecryptInit && !this.nativeDecryptReady && configuredPath && configuredPath !== this.nativeDecryptDllPath) {
|
||||||
|
this.nativeDecryptInit = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.nativeDecryptInit) return this.nativeDecryptReady
|
||||||
|
this.nativeDecryptInit = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
const dllPath = this.resolveWeixinDllPath()
|
||||||
|
if (!dllPath) {
|
||||||
|
this.nativeDecryptError = 'Weixin.dll not found, please set it in Settings or WEFLOW_WEIXIN_DLL'
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const koffi = require('koffi')
|
||||||
|
const kernel32 = koffi.load('kernel32.dll')
|
||||||
|
const getModuleHandleW = kernel32.func('void* __stdcall GetModuleHandleW(str16 lpModuleName)')
|
||||||
|
|
||||||
|
const weixinLib = koffi.load(dllPath)
|
||||||
|
|
||||||
|
let modulePtr = getModuleHandleW('Weixin.dll')
|
||||||
|
if (!modulePtr) modulePtr = getModuleHandleW(basename(dllPath))
|
||||||
|
if (!modulePtr) {
|
||||||
|
this.nativeDecryptError = `GetModuleHandleW 失败: ${dllPath}`
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const base = koffi.address(modulePtr) as bigint
|
||||||
|
const decryptAddr = base + WEIXIN_DLL_OFFSET
|
||||||
|
|
||||||
|
// Koffi requires an external pointer object (not raw Number/BigInt).
|
||||||
|
// Build a temporary uint64 box, decode it to void*, then decode function pointer.
|
||||||
|
const addrBox = new BigUint64Array(1)
|
||||||
|
addrBox[0] = decryptAddr
|
||||||
|
const decryptPtr = koffi.decode(addrBox, 'void *')
|
||||||
|
if (!decryptPtr) {
|
||||||
|
this.nativeDecryptError = `Decode function pointer failed: ${decryptAddr.toString(16)}`
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const decryptProto = koffi.proto('uint64 __fastcall SnsImageDecrypt(void* src, uint64 len, void* dst, uint64 key)')
|
||||||
|
this.nativeDecryptFn = koffi.decode(decryptPtr, decryptProto)
|
||||||
|
this.nativeKoffi = koffi
|
||||||
|
this.nativeWeixinLib = weixinLib
|
||||||
|
this.nativeDecryptReady = true
|
||||||
|
this.nativeDecryptDllPath = dllPath
|
||||||
|
console.info('[SNS] Native decrypt enabled:', this.nativeDecryptDllPath)
|
||||||
|
return true
|
||||||
|
} catch (e: any) {
|
||||||
|
this.nativeDecryptError = e?.message || String(e)
|
||||||
|
this.nativeDecryptReady = false
|
||||||
|
console.warn('[SNS] Native decrypt init failed:', this.nativeDecryptError)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private decryptSnsEncryptedImage(data: Buffer, key: string | number): Buffer {
|
||||||
|
const parsedKey = this.parseSnsKey(key)
|
||||||
|
if (!parsedKey) return data
|
||||||
|
if (!this.ensureNativeDecryptor()) return data
|
||||||
|
|
||||||
|
const out = Buffer.allocUnsafe(data.length)
|
||||||
|
try {
|
||||||
|
this.nativeDecryptFn(
|
||||||
|
data,
|
||||||
|
BigInt(data.length),
|
||||||
|
out,
|
||||||
|
parsedKey
|
||||||
|
)
|
||||||
|
return out
|
||||||
|
} catch (e: any) {
|
||||||
|
this.nativeDecryptError = e?.message || String(e)
|
||||||
|
console.warn('[SNS] Native decrypt call failed:', this.nativeDecryptError)
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async proxyImage(url: string, key?: string | number): Promise<{ success: boolean; dataUrl?: string; error?: string }> {
|
||||||
|
if (!url) return { success: false, error: 'url 不能为空' }
|
||||||
|
const cacheKey = `${url}|${key ?? ''}`
|
||||||
|
|
||||||
|
if (this.imageCache.has(cacheKey)) {
|
||||||
|
return { success: true, dataUrl: this.imageCache.get(cacheKey) }
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@@ -191,12 +310,11 @@ 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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,37 +327,28 @@ 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', () => {
|
||||||
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 shouldDecrypt = xEnc === '1' && key !== undefined && key !== null && String(key).trim().length > 0
|
||||||
const dataUrl = `data:${contentType};base64,${base64}`
|
const decoded = shouldDecrypt ? this.decryptSnsEncryptedImage(raw, key as string | number) : raw
|
||||||
|
|
||||||
// Cache
|
const contentType = detectImageMime(decoded, (res.headers['content-type'] || 'image/jpeg') as string)
|
||||||
this.imageCache.set(url, dataUrl)
|
const dataUrl = `data:${contentType};base64,${decoded.toString('base64')}`
|
||||||
|
|
||||||
|
this.imageCache.set(cacheKey, dataUrl)
|
||||||
resolve({ success: true, dataUrl })
|
resolve({ success: true, dataUrl })
|
||||||
})
|
})
|
||||||
stream.on('error', (e: any) => {
|
stream.on('error', (e: any) => resolve({ success: false, error: e.message }))
|
||||||
resolve({ success: false, error: e.message })
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
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 })
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -34,31 +34,51 @@ 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) => void }) => {
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false)
|
||||||
const { url, thumb, livePhoto } = media;
|
const [resolvedSrc, setResolvedSrc] = useState<string>('')
|
||||||
const isLive = !!livePhoto;
|
const { url, thumb, livePhoto } = media
|
||||||
const targetUrl = thumb || url;
|
const isLive = !!livePhoto
|
||||||
|
const targetUrl = thumb || url
|
||||||
|
|
||||||
const handleDownload = (e: React.MouseEvent) => {
|
useEffect(() => {
|
||||||
e.stopPropagation();
|
let cancelled = false
|
||||||
|
setError(false)
|
||||||
|
setResolvedSrc('')
|
||||||
|
|
||||||
let downloadUrl = url;
|
const run = async () => {
|
||||||
let downloadKey = media.key || '';
|
try {
|
||||||
|
const result = await window.electronAPI.sns.proxyImage({
|
||||||
if (isLive && media.livePhoto) {
|
url: targetUrl,
|
||||||
downloadUrl = media.livePhoto.url;
|
key: media.key
|
||||||
downloadKey = media.livePhoto.key || '';
|
})
|
||||||
|
if (cancelled) return
|
||||||
|
if (result.success && result.dataUrl) {
|
||||||
|
setResolvedSrc(result.dataUrl)
|
||||||
|
} else {
|
||||||
|
setResolvedSrc(targetUrl)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
if (!cancelled) setResolvedSrc(targetUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: 调用后端下载服务
|
run()
|
||||||
// window.electronAPI.sns.download(downloadUrl, downloadKey);
|
return () => { cancelled = true }
|
||||||
};
|
}, [targetUrl, media.key])
|
||||||
|
|
||||||
|
const handleDownload = (e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
// TODO: call backend download service
|
||||||
|
}
|
||||||
|
|
||||||
|
const displaySrc = resolvedSrc || targetUrl
|
||||||
|
const previewSrc = resolvedSrc || url || targetUrl
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`media-item ${error ? 'error' : ''}`} onClick={onPreview}>
|
<div className={`media-item ${error ? 'error' : ''}`} onClick={() => onPreview(previewSrc)}>
|
||||||
<img
|
<img
|
||||||
src={targetUrl}
|
src={displaySrc}
|
||||||
alt=""
|
alt=""
|
||||||
referrerPolicy="no-referrer"
|
referrerPolicy="no-referrer"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
@@ -69,12 +89,12 @@ const MediaItem = ({ media, onPreview }: { media: any, onPreview: () => void })
|
|||||||
<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
|
||||||
@@ -414,7 +434,7 @@ export default function SnsPage() {
|
|||||||
<div className="sns-content-wrapper">
|
<div className="sns-content-wrapper">
|
||||||
<div className="sns-notice-banner">
|
<div className="sns-notice-banner">
|
||||||
<AlertTriangle size={16} />
|
<AlertTriangle size={16} />
|
||||||
<span>由于技术限制,当前无法解密显示部分图片与视频等加密资源文件</span>
|
<span>由于技术限制,当前无法解密显示视频加密资源文件</span>
|
||||||
</div>
|
</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">
|
||||||
@@ -471,7 +491,7 @@ export default function SnsPage() {
|
|||||||
) : post.media.length > 0 && (
|
) : 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) => setPreviewImage(src)} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -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