From 99b61028471dd1c78991af12a9d5a30e960eedca Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Fri, 9 Sep 2022 15:59:43 +0200 Subject: [PATCH] Added deleteMedia to the media controller --- controller/media.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/controller/media.ts b/controller/media.ts index 0bb9ba6..6401f2a 100644 --- a/controller/media.ts +++ b/controller/media.ts @@ -28,4 +28,13 @@ export const getMediaObject = (assetId: string) => Media.findOne({assetId}); * @param assetId The id of the asset to pipe * @param res The express response controller */ -export const pipeMedia = (assetId: string, res: Response) => bucket.file(assetId).createReadStream().pipe(res); \ No newline at end of file +export const pipeMedia = (assetId: string, res: Response) => bucket.file(assetId).createReadStream().pipe(res); + +/** + * Deletes the provided asset from the database & bucket + * @param assetId The id of the asset to delete + */ +export const deleteMedia = async (assetId: string) => { + await Media.deleteOne({assetId}); + await bucket.file(assetId).delete(); +} \ No newline at end of file