Spaces:
Configuration error
Configuration error
Download src/cache/rotation.js from UUUZCX/video-optimizer-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/cache/rotation.js
- Command line
-
hf download hf://spaces/UUUZCX/video-optimizer-bot/src/cache/rotation.js
-
curl -L -o rotation.js https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/cache/rotation.js
1.19 kB
| const fs = require("node:fs/promises"); | |
| const { config } = require("../config/env"); | |
| const { paths } = require("../config/paths"); | |
| const { listFilesRecursive, directorySize, safeUnlink } = require("../utils/fs"); | |
| const { logger } = require("../monitoring/logger"); | |
| async function cleanupTemp() { | |
| const files = await listFilesRecursive(paths.temp); | |
| const cutoff = Date.now() - config.storage.tempRetentionHours * 60 * 60 * 1000; | |
| for (const file of files) { | |
| const stat = await fs.stat(file); | |
| if (stat.mtimeMs < cutoff) await safeUnlink(file); | |
| } | |
| } | |
| async function rotateCache() { | |
| const maxBytes = config.storage.maxCacheSizeGb * 1024 * 1024 * 1024; | |
| let size = await directorySize(paths.cache); | |
| if (size <= maxBytes) return; | |
| const files = await listFilesRecursive(paths.cache); | |
| const stats = await Promise.all(files.map(async (file) => ({ file, stat: await fs.stat(file) }))); | |
| stats.sort((a, b) => a.stat.mtimeMs - b.stat.mtimeMs); | |
| for (const item of stats) { | |
| if (size <= maxBytes * 0.9) break; | |
| await safeUnlink(item.file); | |
| size -= item.stat.size; | |
| } | |
| logger.info({ size }, "Cache rotation completed"); | |
| } | |
| module.exports = { cleanupTemp, rotateCache }; | |