topfans/frontend/utils/handlers/sandboxTmpHandler.js

22 lines
888 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// frontend/utils/handlers/sandboxTmpHandler.js
// 沙盒临时文件 handler简单型
import { scanSandboxTmpFiles, clearAllSandboxTmpFiles } from '@/utils/ioPath'
export default {
id: 'sandbox-tmp',
label: '临时文件',
description: '上传/分享过程产生的临时文件',
warning: false,
async computeSize() {
// scanSandboxTmpFiles 一次返回 {sizeBytes, keyCount}(替代旧的 size+count 双遍历)
return await scanSandboxTmpFiles()
},
async clean() {
// 边量边删clearAllSandboxTmpFiles 内部对每个 tmp/ 目录先 _statDir 拿 before
// 字节/计数,再 removeRecursively返回 { freedBytes, keyCount, ... }
// 调用方不再做 before/after 三次扫描,慢设备不再卡 4s 超时
const r = await clearAllSandboxTmpFiles()
return { freedBytes: r.freedBytes || 0, keyCount: r.keyCount || 0 }
},
}