From a9849d188370fad37b7b59eecd8a9763d0e56576 Mon Sep 17 00:00:00 2001 From: Cohee1207 <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 19 Aug 2023 17:50:16 +0300 Subject: [PATCH] More uploads cleanup --- server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index e73ba35bd..67f62a249 100644 --- a/server.js +++ b/server.js @@ -2076,6 +2076,8 @@ app.post("/importcharacter", urlencodedParser, async function (request, response if (filedata) { if (format == 'json') { fs.readFile(uploadPath, 'utf8', async (err, data) => { + fs.unlinkSync(uploadPath); + if (err) { console.log(err); response.send({ error: true }); @@ -2158,6 +2160,7 @@ app.post("/importcharacter", urlencodedParser, async function (request, response try { let convertedPath = path.join(UPLOADS_PATH, path.basename(uploadPath, ".webp") + ".png") await webp.dwebp(uploadPath, convertedPath, "-o"); + fs.unlinkSync(uploadPath); uploadPath = convertedPath; } catch { @@ -2172,7 +2175,8 @@ app.post("/importcharacter", urlencodedParser, async function (request, response unsetFavFlag(jsonData); jsonData = readFromV2(jsonData); let char = JSON.stringify(jsonData); - charaWrite(uploadPath, char, png_name, response, { file_name: png_name }); + await charaWrite(uploadPath, char, png_name, response, { file_name: png_name }); + fs.unlinkSync(uploadPath); } else if (jsonData.name !== undefined) { console.log('Found a v1 character file.'); @@ -2198,6 +2202,7 @@ app.post("/importcharacter", urlencodedParser, async function (request, response char = convertToV2(char); char = JSON.stringify(char); await charaWrite(uploadPath, char, png_name, response, { file_name: png_name }); + fs.unlinkSync(uploadPath); } else { console.log('Unknown character card format'); response.send({ error: true });