add endpoint to delete image
This commit is contained in:
@@ -33,3 +33,24 @@ async function readImage(id: string) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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