diff --git a/src/storage-file.js b/src/storage-file.js index 61f57fa..2bce871 100644 --- a/src/storage-file.js +++ b/src/storage-file.js @@ -494,7 +494,23 @@ } // 一次性迁移:把老版本存在 IndexedDB 里的图片字节搬到 images/ 下(跑过一次就写标记文件) - const blog = async (m) => { try { await fs().writeTextFile(await join(dir, '_boot.log'), new Date().toISOString() + ' ' + m + '\n', { append: true }) } catch (e) { /* ignore */ } } + // 启动日志:超过 256KB 只保留最后 64KB(否则长年累月会一直长) + const blog = async (m) => { + try { + const logPath = await join(dir, '_boot.log') + let tail = '' + try { + const st = await fs().stat(logPath) + if (st && st.size > 262144) { + const txt = await fs().readTextFile(logPath) + tail = txt.slice(-65536) + } + } catch (e) { /* 文件不存在就是首次 */ } + const line = new Date().toISOString() + ' ' + m + '\n' + if (tail) await fs().writeTextFile(logPath, tail + line) + else await fs().writeTextFile(logPath, line, { append: true }) + } catch (e) { /* ignore */ } + } async function migrateBlobs() { try { await blog('migrate:start dir=' + dir)