fix(data): 清理临时目录时跳过子目录,并回收 multer 残片

transfers/ 下面还套着 multer 的 uploads/ 子目录;原来只清理一层,目录本身会被当成过期文件去 unlink(失败但刷日志),
而 uploads/ 里因体积超限被丢弃的残片又永远不会被清。现在只删普通文件,并两处都清。
This commit is contained in:
Drsakura
2026-10-23 13:52:14 +08:00
parent 5acfbcea7d
commit ee7550c890
2 changed files with 4 additions and 0 deletions
+2
View File
@@ -122,6 +122,8 @@ function cleanupUploads(dir, { maxAgeMs = 24 * 60 * 60 * 1000 } = {}) {
const file = path.join(dir, name)
try {
const stat = fs.statSync(file)
/* 只删普通文件:目录里还套着 multer 的 uploads/,别把目录本身当过期文件删 */
if (!stat.isFile()) continue
if (Date.now() - stat.mtimeMs > maxAgeMs) { fs.unlinkSync(file); removed++ }
} catch { /* 单个文件失败不影响其它清理 */ }
}