mirror of
https://gitlab.w-hs.de/an14051/backerup-website.git
synced 2026-07-27 17:35:29 +00:00
feat: implement file deletion functionality and enhance deployment script
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user