Added deleteMedia to the media controller

This commit is contained in:
Mathias Wagner 2022-09-09 15:59:43 +02:00
parent 4afba19ee9
commit 99b6102847
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -29,3 +29,12 @@ export const getMediaObject = (assetId: string) => Media.findOne({assetId});
* @param res The express response controller
*/
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();
}