Fix media

+ Create media directory on dev start
+ Create media file on POST
This commit is contained in:
Stephan
2022-05-18 08:27:11 +02:00
committed by La_Felx
parent f4288d7319
commit a16126a1db
2 changed files with 5 additions and 5 deletions
+4 -5
View File
@@ -30,7 +30,6 @@ export const uploadImage = async (req: Request, res: Response) => {
// REVIEW: This is only a **quick** fix (As the body is multipart form data, it cannot be used like this)
// @ts-ignore
req.body.description = "Sample image";
console.log(req.body);
if (!req.files || !("file" in req.files)) {
return res.json({
@@ -99,6 +98,10 @@ export const uploadImage = async (req: Request, res: Response) => {
},
});
if (!fs.existsSync("media/" + fileName)) {
file.mv("media/" + fileName, console.error);
}
return res.status(201).json({
type: "success",
payload: { media },
@@ -108,10 +111,6 @@ export const uploadImage = async (req: Request, res: Response) => {
throw new ForwardableError(409, `The image with the the hash and extenstion ${fileName} already exists!`);
}
}
if (!fs.existsSync("media/" + fileName)) {
file.mv("/app/media/" + fileName, console.error);
}
};
export const getAllMedia = async (req: Request, res: Response) => {