add endpoint to delete image

This commit is contained in:
2026-02-04 15:19:38 +13:00
parent d14f3dfdb6
commit 4ccd12a9dc

View File

@@ -32,4 +32,25 @@ async function readImage(id: string) {
'Content-Type': contentType,
}
});
}
export async function DELETE({ params }) {
try {
const { id } = params
await deleteImage(id!)
return httpResponse({ message: 'Image deleted successfully' }, 200);
} catch (error) {
return httpResponse({ error: `Failed to delete image: ${error}` }, 500);
}
}
async function deleteImage(id: string) {
const filepath = join(UPLOAD_DIR, id);
try {
await fs.unlink(filepath);
} catch {
throw new Error('Failed to delete image');
}
}