(cutoffDate: Date)
| 74 | * This is a simple time-based cleanup - removes files older than cutoffDate. |
| 75 | */ |
| 76 | export async function cleanupOldPastes(cutoffDate: Date): Promise<void> { |
| 77 | const pasteDir = getPasteStoreDir() |
| 78 | |
| 79 | let files |
| 80 | try { |
| 81 | files = await readdir(pasteDir) |
| 82 | } catch { |
| 83 | // Directory doesn't exist or can't be read - nothing to clean up |
| 84 | return |
| 85 | } |
| 86 | |
| 87 | const cutoffTime = cutoffDate.getTime() |
| 88 | for (const file of files) { |
| 89 | if (!file.endsWith('.txt')) { |
| 90 | continue |
| 91 | } |
| 92 | |
| 93 | const filePath = join(pasteDir, file) |
| 94 | try { |
| 95 | const stats = await stat(filePath) |
| 96 | if (stats.mtimeMs < cutoffTime) { |
| 97 | await unlink(filePath) |
| 98 | logForDebugging(`Cleaned up old paste: ${filePath}`) |
| 99 | } |
| 100 | } catch { |
| 101 | // Ignore errors for individual files |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 |
no test coverage detected