Team Roles Updates
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user