mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-18 03:57:02 +08:00
feat: 表情包优化
This commit is contained in:
@@ -236,9 +236,27 @@ function listSourceMessages(
|
|||||||
: msgType
|
: msgType
|
||||||
if ([3, 42, 43, 47, 48, 49, 50, 10000, 10002].includes(inferredMsgType)) {
|
if ([3, 42, 43, 47, 48, 49, 50, 10000, 10002].includes(inferredMsgType)) {
|
||||||
try {
|
try {
|
||||||
const parsed =
|
const isQuotePayload = /<refermsg\b/i.test(content)
|
||||||
inferredMsgType === 47
|
const hasStickerHints =
|
||||||
|
/<(?:emoji|sticker|emoticon)\b/i.test(content) ||
|
||||||
|
[
|
||||||
|
'emoji_md5',
|
||||||
|
'emojiMd5',
|
||||||
|
'emoji_cdn_url',
|
||||||
|
'emojiCdnUrl',
|
||||||
|
'packed_info_data',
|
||||||
|
'packed_info',
|
||||||
|
'reserved0',
|
||||||
|
'Reserved0',
|
||||||
|
'WCDB_CT_reserved0'
|
||||||
|
].some((key) => Boolean(msg[key]))
|
||||||
|
const rowSticker =
|
||||||
|
inferredMsgType === 47 || (inferredMsgType === 49 && !isQuotePayload && hasStickerHints)
|
||||||
? parseStickerMessageFromRow(msg, content)
|
? parseStickerMessageFromRow(msg, content)
|
||||||
|
: undefined
|
||||||
|
const parsed =
|
||||||
|
rowSticker?.type === 'sticker'
|
||||||
|
? rowSticker
|
||||||
: parseMessageContent(content, inferredMsgType)
|
: parseMessageContent(content, inferredMsgType)
|
||||||
if (parsed.type === 'system') {
|
if (parsed.type === 'system') {
|
||||||
content = parsed.content
|
content = parsed.content
|
||||||
|
|||||||
+21
-13
@@ -21,6 +21,18 @@ export class StickerService {
|
|||||||
const normalizedMd5 = this.normalizeMd5(md5)
|
const normalizedMd5 = this.normalizeMd5(md5)
|
||||||
let url = String(cdnUrl || '').trim()
|
let url = String(cdnUrl || '').trim()
|
||||||
|
|
||||||
|
const cacheKey =
|
||||||
|
normalizedMd5 || (url ? crypto.createHash('md5').update(url).digest('hex') : '')
|
||||||
|
if (cacheKey) {
|
||||||
|
const cached = await this.readCached(cacheKey)
|
||||||
|
if (cached) return { success: true, data: cached }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (normalizedMd5 && this.wcdb4Client) {
|
||||||
|
const wechatCached = await this.readWechatEmoticonCache(normalizedMd5)
|
||||||
|
if (wechatCached) return { success: true, data: wechatCached }
|
||||||
|
}
|
||||||
|
|
||||||
if (!url && normalizedMd5 && this.wcdb4Client) {
|
if (!url && normalizedMd5 && this.wcdb4Client) {
|
||||||
url = this.wcdb4Client.resolveEmoticonCdnUrl(normalizedMd5) || ''
|
url = this.wcdb4Client.resolveEmoticonCdnUrl(normalizedMd5) || ''
|
||||||
if (!url) {
|
if (!url) {
|
||||||
@@ -32,30 +44,26 @@ export class StickerService {
|
|||||||
return { success: false, error: '未找到表情包 CDN URL' }
|
return { success: false, error: '未找到表情包 CDN URL' }
|
||||||
}
|
}
|
||||||
|
|
||||||
const cacheKey = normalizedMd5 || crypto.createHash('md5').update(url).digest('hex')
|
const resolvedCacheKey = cacheKey || crypto.createHash('md5').update(url).digest('hex')
|
||||||
const cached = await this.readCached(cacheKey)
|
|
||||||
if (cached) return { success: true, data: cached }
|
|
||||||
|
|
||||||
if (normalizedMd5 && this.wcdb4Client) {
|
const pending = downloadCache.get(resolvedCacheKey)
|
||||||
const wechatCached = await this.readWechatEmoticonCache(normalizedMd5)
|
|
||||||
if (wechatCached) return { success: true, data: wechatCached }
|
|
||||||
}
|
|
||||||
|
|
||||||
const pending = downloadCache.get(cacheKey)
|
|
||||||
if (pending) return pending
|
if (pending) return pending
|
||||||
|
|
||||||
const task = this.downloadToDataUrl(url, cacheKey)
|
const task = this.downloadToDataUrl(url, resolvedCacheKey)
|
||||||
downloadCache.set(cacheKey, task)
|
downloadCache.set(resolvedCacheKey, task)
|
||||||
try {
|
try {
|
||||||
return await task
|
return await task
|
||||||
} finally {
|
} finally {
|
||||||
downloadCache.delete(cacheKey)
|
downloadCache.delete(resolvedCacheKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async readCached(cacheKey: string): Promise<string | null> {
|
private async readCached(cacheKey: string): Promise<string | null> {
|
||||||
const extensions = ['.gif', '.png', '.webp', '.jpg', '.jpeg']
|
const extensions = ['.gif', '.png', '.webp', '.jpg', '.jpeg']
|
||||||
const cacheDirs = [this.cacheDir, path.join(os.homedir(), 'Documents', 'WechatExplorer', 'Emojis')]
|
const cacheDirs = [
|
||||||
|
this.cacheDir,
|
||||||
|
path.join(os.homedir(), 'Documents', 'WechatExplorer', 'Emojis')
|
||||||
|
]
|
||||||
for (const cacheDir of cacheDirs) {
|
for (const cacheDir of cacheDirs) {
|
||||||
for (const ext of extensions) {
|
for (const ext of extensions) {
|
||||||
const filePath = path.join(cacheDir, `${cacheKey}${ext}`)
|
const filePath = path.join(cacheDir, `${cacheKey}${ext}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user