Skip to content

Commit

Permalink
fixed deleting files on function uploadFile
Browse files Browse the repository at this point in the history
  • Loading branch information
thoriqazzikraa committed Aug 25, 2023
1 parent 4da1bef commit 51754a5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ async function uploadFile(buffer) {
const filePath = `temp/${Date.now()}.${ext}`;
await fs.writeFileSync(filePath, buffer);
const fileData = fs.readFileSync(filePath);
const form = new formData();
form.append("files[]", fileData, `${Date.now()}.${ext}`);
const { data } = await axios(`https://pomf2.lain.la/upload.php`, {
method: "post",
data: form,
});
return data;
await fs.unlinkSync(filePath);
try {
const form = new formData();
form.append("files[]", fileData, `${Date.now()}.${ext}`);
const { data } = await axios(`https://pomf2.lain.la/upload.php`, {
method: "post",
data: form,
});
return data;
} catch (err) {
console.log(err);
return String(err);
} finally {
fs.unlinkSync(filePath);
}
}

async function enhanceImg(url, scale) {
Expand Down

0 comments on commit 51754a5

Please sign in to comment.