修复api导出图片已有缩略图时 再次导出不会被高清图替代的问题
fix(api): refresh image export cache when larger file is available
This commit is contained in:
1 file changed
+16
-6
@@ -1431,6 +1431,20 @@ class HttpService {
|
|||||||
return '.jpg'
|
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(
|
private async exportMediaForMessages(
|
||||||
messages: Message[],
|
messages: Message[],
|
||||||
talker: string,
|
talker: string,
|
||||||
@@ -1530,9 +1544,7 @@ class HttpService {
|
|||||||
const targetDir = path.join(sessionDir, 'images')
|
const targetDir = path.join(sessionDir, 'images')
|
||||||
const fullPath = path.join(targetDir, fileName)
|
const fullPath = path.join(targetDir, fileName)
|
||||||
this.ensureDir(targetDir)
|
this.ensureDir(targetDir)
|
||||||
if (!fs.existsSync(fullPath)) {
|
this.writeFileIfLarger(fullPath, imageBuffer)
|
||||||
fs.writeFileSync(fullPath, imageBuffer)
|
|
||||||
}
|
|
||||||
const relativePath = `${this.sanitizeFileName(talker, 'session')}/images/${fileName}`
|
const relativePath = `${this.sanitizeFileName(talker, 'session')}/images/${fileName}`
|
||||||
return { kind: 'image', fileName, fullPath, relativePath }
|
return { kind: 'image', fileName, fullPath, relativePath }
|
||||||
}
|
}
|
||||||
@@ -1545,9 +1557,7 @@ class HttpService {
|
|||||||
const targetDir = path.join(sessionDir, 'images')
|
const targetDir = path.join(sessionDir, 'images')
|
||||||
const fullPath = path.join(targetDir, fileName)
|
const fullPath = path.join(targetDir, fileName)
|
||||||
this.ensureDir(targetDir)
|
this.ensureDir(targetDir)
|
||||||
if (!fs.existsSync(fullPath)) {
|
this.writeFileIfLarger(fullPath, imageBuffer)
|
||||||
fs.copyFileSync(imagePath, fullPath)
|
|
||||||
}
|
|
||||||
const relativePath = `${this.sanitizeFileName(talker, 'session')}/images/${fileName}`
|
const relativePath = `${this.sanitizeFileName(talker, 'session')}/images/${fileName}`
|
||||||
return { kind: 'image', fileName, fullPath, relativePath }
|
return { kind: 'image', fileName, fullPath, relativePath }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user