mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
修复部分自定义表情导出后图裂的问题
校验应用缓存、微信 Emoticon 缓存及 CDN 响应的真实图片格式,无效缓存自动回退下载。 增量导出会识别并替换旧归档中的无效表情资源;刷新失败时移除破图引用并保留明确错误。 补充 StickerService 单元测试和 HTML 媒体增量导出回归测试。
This commit is contained in:
1 parent
7016ca1237
commit
36e709d7a6
4 files changed
+230
-26
No files matched your search
+20
-16
@@ -70,16 +70,18 @@ export class StickerService {
|
||||
|
||||
private async readCached(cacheKey: string): Promise<string | null> {
|
||||
const extensions = ['.gif', '.png', '.webp', '.jpg', '.jpeg']
|
||||
const cacheDirs = [
|
||||
this.cacheDir,
|
||||
this.legacyCacheDir
|
||||
]
|
||||
const cacheDirs = [this.cacheDir, this.legacyCacheDir]
|
||||
for (const cacheDir of cacheDirs) {
|
||||
for (const ext of extensions) {
|
||||
const filePath = path.join(cacheDir, `${cacheKey}${ext}`)
|
||||
if (!fs.existsSync(filePath)) continue
|
||||
const buffer = await fs.readFile(filePath)
|
||||
return this.toDataUrl(buffer, ext)
|
||||
const detectedExtension = this.detectExtension(buffer)
|
||||
if (!detectedExtension) {
|
||||
console.warn(`[StickerService] ignored invalid local cache key=${cacheKey}`)
|
||||
continue
|
||||
}
|
||||
return this.toDataUrl(buffer, detectedExtension)
|
||||
}
|
||||
}
|
||||
return null
|
||||
@@ -108,7 +110,11 @@ export class StickerService {
|
||||
const filePath = path.join(cacheRoot, month, 'Emoticon', prefix, md5)
|
||||
if (!fs.existsSync(filePath)) continue
|
||||
const buffer = await fs.readFile(filePath)
|
||||
const ext = this.detectExtension(buffer) || '.gif'
|
||||
const ext = this.detectExtension(buffer)
|
||||
if (!ext) {
|
||||
console.warn(`[StickerService] ignored invalid WeChat cache md5=${md5} month=${month}`)
|
||||
continue
|
||||
}
|
||||
return this.toDataUrl(buffer, ext)
|
||||
}
|
||||
|
||||
@@ -169,7 +175,14 @@ export class StickerService {
|
||||
return
|
||||
}
|
||||
|
||||
const ext = this.detectExtension(buffer) || this.getExtFromUrl(url) || '.gif'
|
||||
const ext = this.detectExtension(buffer)
|
||||
if (!ext) {
|
||||
console.warn(
|
||||
`[StickerService] download returned invalid image md5=${cacheKey} host=${this.getUrlHost(url)}`
|
||||
)
|
||||
resolve({ success: false, error: '表情包响应不是支持的图片格式' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
await fs.ensureDir(this.cacheDir)
|
||||
await fs.writeFile(path.join(this.cacheDir, `${cacheKey}${ext}`), buffer)
|
||||
@@ -208,15 +221,6 @@ export class StickerService {
|
||||
return null
|
||||
}
|
||||
|
||||
private getExtFromUrl(url: string): string | null {
|
||||
try {
|
||||
const ext = path.extname(new URL(url).pathname).toLowerCase()
|
||||
return ['.gif', '.png', '.webp', '.jpg', '.jpeg'].includes(ext) ? ext : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private getUrlHost(url: string): string {
|
||||
try {
|
||||
return new URL(url).hostname || 'unknown'
|
||||
|
||||
Reference in new issue
Block a user