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

Loading…
Cancel
Save