mirror of
https://github.com/detleph/server.git
synced 2026-09-04 00:26:03 +02:00
Fix media
+ Create media directory on dev start + Create media file on POST
This commit is contained in:
@@ -4,6 +4,7 @@ if ! test -f INITIALIZED; then
|
||||
touch INITIALIZED
|
||||
|
||||
cd /app
|
||||
mkdir media
|
||||
|
||||
npm i -g ts-node nodemon
|
||||
npm i
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user