add endpoint to delete image
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user