From 7551d1a0cc0039dfefc19ec1d4d6c05bea52ea3f Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Fri, 9 Sep 2022 15:23:30 +0200 Subject: [PATCH] Created the media controller --- controller/media.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 controller/media.ts diff --git a/controller/media.ts b/controller/media.ts new file mode 100644 index 0000000..ceb43b8 --- /dev/null +++ b/controller/media.ts @@ -0,0 +1,25 @@ +import {Media} from "../models/Media"; +import {Response} from "express"; +import {bucket} from "./bucket"; + +/** + * Creates a new media in the database + * @param clientId The client id of the uploader + * @param assetName The name of the asset + * @param assetEnding The file ending of the asset + */ +export const createMedia = (clientId: number, assetName: string, assetEnding: string) => + Media.create({clientId, assetName, assetEnding}); + +/** + * Gets a media object by the asset id + * @param assetId The id of the asset to search + */ +export const getMediaObject = (assetId: string) => Media.findOne({assetId}); + +/** + * Pipes the provided asset into an express response + * @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