From 85cc03300fa8feabab574c8a6293cc112a9598e5 Mon Sep 17 00:00:00 2001 From: fatchan Date: Sun, 5 May 2019 16:16:48 +0000 Subject: [PATCH] more readable delete and remove inaccurate log for amount deleted --- deletescheduler.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/deletescheduler.js b/deletescheduler.js index e7feca9b..3d14cdd7 100644 --- a/deletescheduler.js +++ b/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) {