From db4fab9130c72b5cb3b218ce013bdcd58e40ab92 Mon Sep 17 00:00:00 2001 From: The Shit Code Here Date: Fri, 20 Feb 2026 20:55:31 +0700 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DHTML=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=96=87=E4=BB=B6=E5=90=8D=E5=86=B2=E7=AA=81?= =?UTF-8?q?=20(#282)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 0xshitcode <0xshitcode@users.noreply.github.com> --- electron/services/exportService.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/electron/services/exportService.ts b/electron/services/exportService.ts index be1a653..8d4fbf5 100644 --- a/electron/services/exportService.ts +++ b/electron/services/exportService.ts @@ -1479,13 +1479,17 @@ class ExportService { result.localPath = thumbResult.localPath } + // 为每条消息生成稳定且唯一的文件名前缀,避免跨日期/消息发生同名覆盖 + const messageId = String(msg.localId || Date.now()) + const imageKey = (imageMd5 || imageDatName || 'image').replace(/[^a-zA-Z0-9_-]/g, '') + // 从 data URL 或 file URL 获取实际路径 let sourcePath = result.localPath if (sourcePath.startsWith('data:')) { // 是 data URL,需要保存为文件 const base64Data = sourcePath.split(',')[1] const ext = this.getExtFromDataUrl(sourcePath) - const fileName = `${imageMd5 || imageDatName || msg.localId}${ext}` + const fileName = `${messageId}_${imageKey}${ext}` const destPath = path.join(imagesDir, fileName) fs.writeFileSync(destPath, Buffer.from(base64Data, 'base64')) @@ -1501,7 +1505,7 @@ class ExportService { // 复制文件 if (!fs.existsSync(sourcePath)) return null const ext = path.extname(sourcePath) || '.jpg' - const fileName = `${imageMd5 || imageDatName || msg.localId}${ext}` + const fileName = `${messageId}_${imageKey}${ext}` const destPath = path.join(imagesDir, fileName) if (!fs.existsSync(destPath)) { @@ -4769,4 +4773,3 @@ class ExportService { } export const exportService = new ExportService() -