fix(download): 文件版加固(路径白名单/tokio 写盘/缩略图预热/临时清理/开关保留)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 1m8s

This commit is contained in:
qiqi committed 2026-12-04 12:32:46 +08:00
1 parent df3e99b0ee
commit 9f8fb273d1
11 files changed
+84 -16

No files matched your search

+37 -2
View File
@@ -1112,6 +1112,20 @@
}
// 2026-12-04(文件版下载,默认关闭):把 Rust 已下载好的临时文件**接管**进资产库。
// 与 kv.put(Blob) 等价,但不经过 base64:同卷 rename,跨卷 copy+remove,然后登记 assets。
// 2026-12-04:文件接管后按路径生成一张小缩略图(dataURL),供显示层 prime,避免首帧整幅解码原图。
async function displayThumbDataUrlOfRef (ref, max) {
try {
const key = String(ref && ref.__blob ? ref.__blob : '')
const a = key ? assets[key] : null
if (!a || !a.f) return ''
const m = Math.max(64, Number(max) || 320)
const h16 = await sha16(new TextEncoder().encode('file:' + key))
const r = await makeDisplayThumbFromPath(h16, await join(dir, a.f), m)
if (!r) return ''
return await readDisplayThumb(h16, m)
} catch (e) { return '' }
}
async function putFileFrom (srcPath, opt) {
try {
if (!enabled() || !dir) return null
@@ -1324,11 +1338,32 @@
}
// v3.25.80:启动维护入口(缩略图封顶 + legacy 未引用清理),宿主只调这一个
// 2026-12-04:文件版下载的临时目录清理(失败/崩溃会留下 .bin;保留 24h 内,其余删)
async function cleanupCacheTmp () {
try {
if (!enabled() || !dir) return 0
const tdir = await join(dir, 'cache', 'tmp')
if (!(await fs().exists(tdir))) return 0
const ents = await fs().readDir(tdir)
const cutoff = Date.now() - 24 * 3600e3
let n = 0
for (const e of ents) {
if (!e || e.isDirectory) continue
try {
const st = await fs().stat(await join(tdir, e.name))
if (!st || Number(st.mtimeMs || 0) < cutoff) { await fs().remove(await join(tdir, e.name)); n++ }
} catch (err) { /* ignore */ }
}
return n
} catch (e) { return 0 }
}
async function maintain (opts) {
const o = opts || {}
const a = await pruneThumbs(o.maxMB).catch(() => 0)
const b = await cleanupLegacy(o.keep).catch(() => 0)
return { thumbs: a, legacy: b }
const c = await cleanupCacheTmp().catch(() => 0)
return { thumbs: a, legacy: b, tmp: c }
}
// v3.26.123:原生缩略图。有就返回,没有就让 Rust 按目标尺寸解码/缩放/编码后写盘,再读成 objectURL。
@@ -1692,7 +1727,7 @@
enabled, ready: init, flush,
// 供其它模块把诊断写进 _boot.log(v3.26.109)
logLine: (m) => blog(m),
runtime, pickDir, switchTo, migrateTo, deleteImageBytes, deleteGalleryBytesFor, galleryAudit, gcImages, rotateTrash, galleryThumb, galleryThumbUrl, galleryThumbOfEntry, galleryOriginalOf, galleryOriginalBlob, putFileFrom, readDisplayThumb, readDisplayThumbUrl, makeDisplayThumb, makeDisplayThumbFromPath, resizeDataUrl, decodeStats, thumbStats, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs, cleanupLegacy, maintain,
runtime, pickDir, switchTo, migrateTo, deleteImageBytes, deleteGalleryBytesFor, galleryAudit, gcImages, rotateTrash, galleryThumb, galleryThumbUrl, galleryThumbOfEntry, galleryOriginalOf, galleryOriginalBlob, putFileFrom, displayThumbDataUrlOfRef, readDisplayThumb, readDisplayThumbUrl, makeDisplayThumb, makeDisplayThumbFromPath, resizeDataUrl, decodeStats, thumbStats, writeDisplayThumb, writeDisplayThumbBlob, pruneThumbs, cleanupLegacy, maintain,
plugins: { manifest: pluginManifest, read: pluginRead, write: pluginWrite, remove: pluginRemove, dir: pluginDir, listLocal: pluginListLocal, listDirs: pluginListDirs, readFile: pluginReadFile, writeFile: pluginWriteFile, writeBinary: pluginWriteBinary, mkdir: pluginMkdir, removeDir: pluginRemoveDir, renameDir: pluginRenameDir, existsDir: pluginExistsDir },
pluginData: { read: pluginDataRead, write: pluginDataWrite, remove: pluginDataRemove, list: pluginDataList },
pluginFiles: { put: pluginFilePut, get: pluginFileGet, list: pluginFileList, remove: pluginFileRemove, stat: pluginFileStat, dir: pluginFilesDir, readBytes: pluginFileReadBytes, listAll: pluginFilesListAll },
+1 -1
View File
@@ -1450,7 +1450,7 @@ function GSetGroup (props) {
security: { password: draft.sec.clear ? '__CLEAR__' : ((draft.sec.password && draft.sec.password.trim()) || (draft.sec.hasPassword ? '__KEEP__' : '')) },
// autoSaveImages 已废弃(v3.25.33):保留归一化只为老配置兼容,不再驱动任何下载;
// 「出图自动保存」见 设置 → 图片导出目录 → 自动下载。
canvas: { hotkeys: Object.assign({}, HOTKEY_DEFAULTS, draft.canvas.hotkeys || {}), appearance: (function () { const A = (typeof window !== 'undefined') ? window.IWBUIApearance : null; return A ? A.normalize(draft) : ((draft.canvas && draft.canvas.appearance) || {}) })(), sizePresets: Array.isArray(draft.canvas.sizePresets) && draft.canvas.sizePresets.length ? draft.canvas.sizePresets : RATIOS, generationConcurrency: Math.max(GEN_CONCURRENCY_MIN, Math.min(GEN_CONCURRENCY_MAX, Number(draft.canvas.generationConcurrency) || GEN_CONCURRENCY_DEFAULT)), taskStallEndMs: Math.max(TASK_STALL_END_MIN, Math.min(TASK_STALL_END_MAX, Number(draft.canvas.taskStallEndMs) || 300000)), autoSaveImages: draft.canvas.autoSaveImages !== false, backupOriginals: true, lodLowZoom: draft.canvas.lodLowZoom !== false, newBadgeSec: Number.isFinite(Number(draft.canvas.newBadgeSec)) ? Math.max(0, Math.min(3600, Number(draft.canvas.newBadgeSec))) : 120, downloadConcurrency: Math.max(1, Math.min(64, Number(draft.canvas.downloadConcurrency) || 30)) },
canvas: { hotkeys: Object.assign({}, HOTKEY_DEFAULTS, draft.canvas.hotkeys || {}), appearance: (function () { const A = (typeof window !== 'undefined') ? window.IWBUIApearance : null; return A ? A.normalize(draft) : ((draft.canvas && draft.canvas.appearance) || {}) })(), sizePresets: Array.isArray(draft.canvas.sizePresets) && draft.canvas.sizePresets.length ? draft.canvas.sizePresets : RATIOS, generationConcurrency: Math.max(GEN_CONCURRENCY_MIN, Math.min(GEN_CONCURRENCY_MAX, Number(draft.canvas.generationConcurrency) || GEN_CONCURRENCY_DEFAULT)), taskStallEndMs: Math.max(TASK_STALL_END_MIN, Math.min(TASK_STALL_END_MAX, Number(draft.canvas.taskStallEndMs) || 300000)), autoSaveImages: draft.canvas.autoSaveImages !== false, backupOriginals: true, lodLowZoom: draft.canvas.lodLowZoom !== false, newBadgeSec: Number.isFinite(Number(draft.canvas.newBadgeSec)) ? Math.max(0, Math.min(3600, Number(draft.canvas.newBadgeSec))) : 120, downloadConcurrency: Math.max(1, Math.min(64, Number(draft.canvas.downloadConcurrency) || 30)), rustFileDownload: draft.canvas.rustFileDownload === true },
webhook: { enabled: !!draft.webhook.enabled, url: (draft.webhook.url || '').trim() },
})
setSaving(false)