feat: implement file deletion functionality and enhance deployment script

This commit is contained in:
Anders Böttcher
2026-05-13 12:35:58 +02:00
parent cf23467be6
commit 9dbbf814b4
10 changed files with 229 additions and 50 deletions
+13
View File
@@ -92,3 +92,16 @@ export function getUploadPath(token: string, originalName: string): string {
return path.join(UPLOADS_DIR, token, originalName)
}
export async function deleteFile(token: string): Promise<void> {
await ensureReady()
const record = await getFile(token)
if (!record) throw new Error('File not found')
// Remove from DB first
await getDb().execute({ sql: 'DELETE FROM files WHERE token = ?', args: [token] })
// Remove upload directory (best-effort — don't fail if already gone)
const dir = path.join(UPLOADS_DIR, token)
await fs.rm(dir, { recursive: true, force: true })
}