More uploads cleanup

This commit is contained in:
Cohee1207 2023-08-19 17:50:16 +03:00
parent 6471ce2074
commit a9849d1883
1 changed files with 6 additions and 1 deletions

View File

@ -2076,6 +2076,8 @@ app.post("/importcharacter", urlencodedParser, async function (request, response
if (filedata) { if (filedata) {
if (format == 'json') { if (format == 'json') {
fs.readFile(uploadPath, 'utf8', async (err, data) => { fs.readFile(uploadPath, 'utf8', async (err, data) => {
fs.unlinkSync(uploadPath);
if (err) { if (err) {
console.log(err); console.log(err);
response.send({ error: true }); response.send({ error: true });
@ -2158,6 +2160,7 @@ app.post("/importcharacter", urlencodedParser, async function (request, response
try { try {
let convertedPath = path.join(UPLOADS_PATH, path.basename(uploadPath, ".webp") + ".png") let convertedPath = path.join(UPLOADS_PATH, path.basename(uploadPath, ".webp") + ".png")
await webp.dwebp(uploadPath, convertedPath, "-o"); await webp.dwebp(uploadPath, convertedPath, "-o");
fs.unlinkSync(uploadPath);
uploadPath = convertedPath; uploadPath = convertedPath;
} }
catch { catch {
@ -2172,7 +2175,8 @@ app.post("/importcharacter", urlencodedParser, async function (request, response
unsetFavFlag(jsonData); unsetFavFlag(jsonData);
jsonData = readFromV2(jsonData); jsonData = readFromV2(jsonData);
let char = JSON.stringify(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) { } else if (jsonData.name !== undefined) {
console.log('Found a v1 character file.'); console.log('Found a v1 character file.');
@ -2198,6 +2202,7 @@ app.post("/importcharacter", urlencodedParser, async function (request, response
char = convertToV2(char); char = convertToV2(char);
char = JSON.stringify(char); char = JSON.stringify(char);
await 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 { } else {
console.log('Unknown character card format'); console.log('Unknown character card format');
response.send({ error: true }); response.send({ error: true });