more readable delete and remove inaccurate log for amount deleted

merge-requests/208/head
fatchan 5 years ago
parent 3ffa8ef51a
commit 85cc03300f
  1. 18
      deletescheduler.js

@ -12,17 +12,17 @@ async function deleteCaptchas() {
try { try {
const files = await readdir(`${uploadDirectory}captcha/`); const files = await readdir(`${uploadDirectory}captcha/`);
if (files.length > 0) { if (files.length > 0) {
console.log('Deleting old captchas:', files); files.forEach(async (file) => {
files.forEach(file => {
const filePath = `${uploadDirectory}captcha/${file}`; const filePath = `${uploadDirectory}captcha/${file}`;
stat(filePath).then(stats => { const stats = await stat(filePath).catch(e => console.error);
const now = Date.now(); if (!stats) {
const expiry = new Date(stats.ctime).getTime() + 6*1000*60; //6 minutes ahead
if (now > expiry) {
return unlink(filePath);
}
return; return;
}).catch(e => console.error); }
const now = Date.now();
const expiry = new Date(stats.ctime).getTime() + 6*1000*60; //6 minutes ahead
if (now > expiry) {
await unlink(filePath).catch(e => console.error);
}
}); });
} }
} catch (err) { } catch (err) {

Loading…
Cancel
Save