mirror of
https://github.com/detleph/server.git
synced 2026-09-04 08:36:06 +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
|
touch INITIALIZED
|
||||||
|
|
||||||
cd /app
|
cd /app
|
||||||
|
mkdir media
|
||||||
|
|
||||||
npm i -g ts-node nodemon
|
npm i -g ts-node nodemon
|
||||||
npm i
|
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)
|
// REVIEW: This is only a **quick** fix (As the body is multipart form data, it cannot be used like this)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
req.body.description = "Sample image";
|
req.body.description = "Sample image";
|
||||||
console.log(req.body);
|
|
||||||
|
|
||||||
if (!req.files || !("file" in req.files)) {
|
if (!req.files || !("file" in req.files)) {
|
||||||
return res.json({
|
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({
|
return res.status(201).json({
|
||||||
type: "success",
|
type: "success",
|
||||||
payload: { media },
|
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!`);
|
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) => {
|
export const getAllMedia = async (req: Request, res: Response) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user