diff --git a/src/routes/api/image/[id]/+server.ts b/src/routes/api/image/[id]/+server.ts index 854891b..44a0be8 100644 --- a/src/routes/api/image/[id]/+server.ts +++ b/src/routes/api/image/[id]/+server.ts @@ -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'); + } } \ No newline at end of file