From 8f722276f329b68d0f5fac395c89713813983e1a Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 6 Nov 2023 13:32:48 -0500 Subject: [PATCH] Delete existing attachments --- tools/download-stats.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/download-stats.js b/tools/download-stats.js index 5925a5f1..86f0e037 100644 --- a/tools/download-stats.js +++ b/tools/download-stats.js @@ -33,6 +33,21 @@ This page was automatically generated on ${formattedDate}. fs.writeFileSync(markdownFile, markdownContent); } +async function deleteExistingAttachments() { + try { + const files = fs.readdirSync(attachmentDestination); + + for (const file of files) { + if (path.extname(file) === '.png') { + fs.unlinkSync(path.join(attachmentDestination, file)); + console.log(`Deleted ${file}`); + } + } + } catch (error) { + console.error(error); + } +} + const config = getEnvVars(['EMAIL', 'EMAIL_APP_PASSWORD']); const imap = new Imap({ @@ -111,6 +126,8 @@ imap.once('ready', async () => { const yesterday = new Date(now - 24 * 60 * 60 * 1000); const yesterdayString = yesterday.toISOString().slice(0, 19).replace('T', ' '); + deleteExistingAttachments(); + const images = [] images.push({ title: 'Channel Health',