Merge pull request #1003 from Moxiaoyuan1003/fix/sns-thumb-and-backup-v2
fix: 修复朋友圈图片显示"已删除"和数据库备份卡住的两个 Bug
This commit is contained in:
2 files changed
+14
-2
No files matched your search
@@ -468,10 +468,10 @@ export class BackupService {
|
||||
)
|
||||
if (!opened) {
|
||||
const detail = await wcdbService.getLastInitError().catch(() => null)
|
||||
return { success: false, error: detail || `目标账号 ${accountDirName} 数据库连接失败` }
|
||||
return { success: false, error: detail || `目标账号 ${accountDir} 数据库连接失败` }
|
||||
}
|
||||
|
||||
return { success: true, wxid: accountDirName, dbPath, dbStorage }
|
||||
return { success: true, wxid: accountDir, dbPath, dbStorage }
|
||||
}
|
||||
|
||||
private buildDbId(kind: BackupDbKind, index: number, dbPath: string): string {
|
||||
@@ -858,10 +858,13 @@ export class BackupService {
|
||||
if (!existsSync(manifestPath)) return { success: false, error: '备份包缺少 manifest.json' }
|
||||
const manifest = JSON.parse(await readFileAsync(manifestPath, 'utf8')) as BackupManifest
|
||||
if (manifest?.type !== 'weflow-db-snapshots' || manifest.version !== 1) {
|
||||
emitBackupProgress({ phase: 'failed', message: '不支持的备份包格式' })
|
||||
return { success: false, error: '不支持的备份包格式' }
|
||||
}
|
||||
emitBackupProgress({ phase: 'done', message: '备份包已读取' })
|
||||
return { success: true, manifest }
|
||||
} catch (e) {
|
||||
emitBackupProgress({ phase: 'failed', message: e instanceof Error ? e.message : String(e) })
|
||||
return { success: false, error: e instanceof Error ? e.message : String(e) }
|
||||
} finally {
|
||||
if (extractDir) {
|
||||
|
||||
@@ -2080,6 +2080,8 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
|
||||
const zlib = require('zlib')
|
||||
const urlObj = new URL(url)
|
||||
|
||||
console.log(`[SnsService] 开始下载图片: url=${url.substring(0, 100)}..., key=${key || 'undefined'}`)
|
||||
|
||||
const options = {
|
||||
hostname: urlObj.hostname,
|
||||
path: urlObj.pathname + urlObj.search,
|
||||
@@ -2094,7 +2096,9 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
|
||||
}
|
||||
|
||||
const req = https.request(options, (res: any) => {
|
||||
console.log(`[SnsService] CDN 响应: statusCode=${res.statusCode}, x-enc=${res.headers['x-enc']}, content-type=${res.headers['content-type']}`)
|
||||
if (res.statusCode !== 200 && res.statusCode !== 206) {
|
||||
console.error(`[SnsService] CDN 请求失败: HTTP ${res.statusCode}`)
|
||||
resolve({ success: false, error: `HTTP ${res.statusCode}` })
|
||||
return
|
||||
}
|
||||
@@ -2114,9 +2118,11 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
|
||||
|
||||
let decoded = raw
|
||||
const rawMagicMime = detectImageMime(raw, '')
|
||||
console.log(`[SnsService] 原始数据: size=${raw.length}, mime=${rawMagicMime}, xEnc=${xEnc}`)
|
||||
|
||||
// 图片逻辑
|
||||
const shouldDecrypt = (xEnc === '1' || !!key) && key !== undefined && key !== null && String(key).trim().length > 0
|
||||
console.log(`[SnsService] 解密判断: shouldDecrypt=${shouldDecrypt}, key=${key || 'undefined'}`)
|
||||
if (shouldDecrypt) {
|
||||
try {
|
||||
const keyStr = String(key).trim()
|
||||
@@ -2132,6 +2138,7 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
|
||||
}
|
||||
|
||||
const decryptedMagicMime = detectImageMime(decrypted, '')
|
||||
console.log(`[SnsService] 解密后: mime=${decryptedMagicMime}`)
|
||||
if (decryptedMagicMime.startsWith('image/')) {
|
||||
decoded = decrypted
|
||||
} else if (!rawMagicMime.startsWith('image/')) {
|
||||
@@ -2144,7 +2151,9 @@ window.addEventListener('scroll',function(){document.getElementById('btt').class
|
||||
}
|
||||
|
||||
const decodedMagicMime = detectImageMime(decoded, '')
|
||||
console.log(`[SnsService] 最终结果: mime=${decodedMagicMime}, isImage=${decodedMagicMime.startsWith('image/')}`)
|
||||
if (!decodedMagicMime.startsWith('image/')) {
|
||||
console.error(`[SnsService] 图片解密失败: 原始mime=${rawMagicMime}, 解密后mime=${decodedMagicMime}, key=${key}`)
|
||||
resolve({ success: false, error: '图片解密失败:无法识别图片格式' })
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user