mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-16 18:25:17 +02:00
retention 7 days
This commit is contained in:
parent
e314a83e2e
commit
f563f5ecae
1 changed files with 25 additions and 0 deletions
|
|
@ -215,11 +215,36 @@ app.post('/browse/config', (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const PORT = 3001;
|
const PORT = 3001;
|
||||||
|
const RETENTION_DAYS = 7;
|
||||||
|
const CLEANUP_INTERVAL_MS = 60 * 60 * 1000; // 1 hour
|
||||||
|
|
||||||
|
function cleanUpOldFiles(): void {
|
||||||
|
if (!fs.existsSync(CAPTURED_PAGES_DIR)) return;
|
||||||
|
|
||||||
|
const cutoff = new Date();
|
||||||
|
cutoff.setDate(cutoff.getDate() - RETENTION_DAYS);
|
||||||
|
const cutoffStr = cutoff.toISOString().slice(0, 10); // YYYY-MM-DD
|
||||||
|
|
||||||
|
for (const dateEntry of fs.readdirSync(CAPTURED_PAGES_DIR)) {
|
||||||
|
// only process date-formatted directories
|
||||||
|
if (!/^\d{4}-\d{2}-\d{2}$/.test(dateEntry)) continue;
|
||||||
|
if (dateEntry >= cutoffStr) continue;
|
||||||
|
|
||||||
|
const datePath = path.join(CAPTURED_PAGES_DIR, dateEntry);
|
||||||
|
if (!fs.statSync(datePath).isDirectory()) continue;
|
||||||
|
|
||||||
|
fs.rmSync(datePath, { recursive: true, force: true });
|
||||||
|
console.log(`[ChromeSync] Cleaned up old captures: ${dateEntry}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function init(): Promise<void> {
|
export async function init(): Promise<void> {
|
||||||
fs.mkdirSync(CAPTURED_PAGES_DIR, { recursive: true });
|
fs.mkdirSync(CAPTURED_PAGES_DIR, { recursive: true });
|
||||||
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
||||||
|
|
||||||
|
cleanUpOldFiles();
|
||||||
|
setInterval(cleanUpOldFiles, CLEANUP_INTERVAL_MS);
|
||||||
|
|
||||||
app.listen(PORT, 'localhost', () => {
|
app.listen(PORT, 'localhost', () => {
|
||||||
console.log('[ChromeSync] Server starting.');
|
console.log('[ChromeSync] Server starting.');
|
||||||
console.log(` Captured pages: ${CAPTURED_PAGES_DIR}`);
|
console.log(` Captured pages: ${CAPTURED_PAGES_DIR}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue