Team Roles Updates

This commit is contained in:
2025-11-23 13:35:43 -05:00
parent c3e52d6a03
commit 758bef92c7
8 changed files with 131 additions and 6 deletions
+44
View File
@@ -112,4 +112,48 @@ ${typstCode}
return result.files[0];
}
async cleanupOldFiles(daysOld: number = 1): Promise<{ deleted: number; errors: number }> {
const storageDir = path.resolve('./storage/typst');
let deleted = 0;
let errors = 0;
try {
await fs.promises.access(storageDir);
} catch {
console.log('[Typst] Storage directory does not exist, nothing to clean');
return { deleted: 0, errors: 0 };
}
try {
const files = await fs.promises.readdir(storageDir);
const now = Date.now();
const threshold = daysOld * 24 * 60 * 60 * 1000; // Convert days to milliseconds
for (const file of files) {
const filePath = path.join(storageDir, file);
try {
const stats = await fs.promises.stat(filePath);
const fileAge = now - stats.mtimeMs;
if (fileAge > threshold) {
await fs.promises.unlink(filePath);
deleted++;
console.log(`[Typst] Deleted old file: ${file}`);
}
} catch (err) {
console.error(`[Typst] Error processing file ${file}:`, err);
errors++;
}
}
console.log(`[Typst] Cleanup complete: ${deleted} files deleted, ${errors} errors`);
} catch (err) {
console.error('[Typst] Error during cleanup:', err);
errors++;
}
return { deleted, errors };
}
}