From 876bd73c5696e80a263829ccb10869b0243880aa Mon Sep 17 00:00:00 2001 From: "Jonny_Bro (Nikita)" Date: Thu, 29 Aug 2024 12:10:16 +0500 Subject: [PATCH] Update api res when uploading from site --- routes/api.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routes/api.js b/routes/api.js index a8d47b6..f77cea5 100644 --- a/routes/api.js +++ b/routes/api.js @@ -122,7 +122,7 @@ router.post("/upload_site", isUser, async (req, res) => { const form = formidable({ maxFileSize: 10 * 1024 * 1024 }); form.parse(req, async (err, fields, files) => { - if (err) return res.send("Error while uploading file. Please contact the administrator."); + if (err) return res.status(401).send("Error while uploading file. Please contact the administrator."); const uploaded = fs.readFileSync(files.file.filepath); @@ -133,7 +133,7 @@ router.post("/upload_site", isUser, async (req, res) => { course = uploaded; } - if (!isCourseFileValid(JSON.parse(course))) return res.status(401).json({ res: res.statusCode, message: "Invalid course file. Please provide a valid course." }); + if (!isCourseFileValid(JSON.parse(course))) return res.status(401).send("Invalid course file. Please provide a valid course."); let code = generateCode(); let file = `public/courses/${code}.txt`; @@ -167,7 +167,7 @@ router.post("/upload_site", isUser, async (req, res) => { `[UPLOAD] User uploaded a course from the site (Course: ${code}, SteamID: ${user.steamid}, Key ${user.authKey}).`, `[UPLOAD] User uploaded a course from the site (Course: \`${code}\`, SteamID: \`${user.steamid}\`, Key \`${user.authKey}\`).`, ); - res.send({ res: res.statusCode, code: code }); + res.send(`Uploaded successfully! Your code is ${code}`); }); });