mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-05-27 15:11:23 +00:00
fix(api): refresh image export cache when larger file is available
This commit is contained in:
@@ -1417,6 +1417,20 @@ class HttpService {
|
||||
return '.jpg'
|
||||
}
|
||||
|
||||
private writeFileIfLarger(fullPath: string, data: Buffer): void {
|
||||
if (fs.existsSync(fullPath)) {
|
||||
try {
|
||||
const stat = fs.statSync(fullPath)
|
||||
if (!stat.isFile()) return
|
||||
if (data.length <= stat.size) return
|
||||
} catch {
|
||||
// If the existing export cannot be inspected, overwrite it below.
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(fullPath, data)
|
||||
}
|
||||
|
||||
private async exportMediaForMessages(
|
||||
messages: Message[],
|
||||
talker: string,
|
||||
@@ -1516,9 +1530,7 @@ class HttpService {
|
||||
const targetDir = path.join(sessionDir, 'images')
|
||||
const fullPath = path.join(targetDir, fileName)
|
||||
this.ensureDir(targetDir)
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
fs.writeFileSync(fullPath, imageBuffer)
|
||||
}
|
||||
this.writeFileIfLarger(fullPath, imageBuffer)
|
||||
const relativePath = `${this.sanitizeFileName(talker, 'session')}/images/${fileName}`
|
||||
return { kind: 'image', fileName, fullPath, relativePath }
|
||||
}
|
||||
@@ -1531,9 +1543,7 @@ class HttpService {
|
||||
const targetDir = path.join(sessionDir, 'images')
|
||||
const fullPath = path.join(targetDir, fileName)
|
||||
this.ensureDir(targetDir)
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
fs.copyFileSync(imagePath, fullPath)
|
||||
}
|
||||
this.writeFileIfLarger(fullPath, imageBuffer)
|
||||
const relativePath = `${this.sanitizeFileName(talker, 'session')}/images/${fileName}`
|
||||
return { kind: 'image', fileName, fullPath, relativePath }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user