From 0cc853f86b6ea6e603534774d2e3c811ee3e0a35 Mon Sep 17 00:00:00 2001 From: Martin Grisard Date: Sun, 22 Nov 2020 12:27:19 +0100 Subject: [PATCH 1/2] snychronized deletion of old png files snychronized deletion of old png files --- node_helper.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node_helper.js b/node_helper.js index a7f7da0..272118a 100644 --- a/node_helper.js +++ b/node_helper.js @@ -18,9 +18,11 @@ module.exports = NodeHelper.create({ host: payload.domain, path: payload.path }; + var pngFiles = payload.mmDir + 'modules/mmm-weatherchart/cache/*.png'; + del.sync([pngFiles]); + http.get(options, function (response) { - var pngFiles = payload.mmDir + 'modules/mmm-weatherchart/cache/*.png'; - del([pngFiles]); + var cachedFile = 'modules/mmm-weatherchart/cache/map-' + new Date().getTime() + '.png'; var newImage = fs.createWriteStream(payload.mmDir + cachedFile); response.on('data', function(chunk){ From 4eb2b99ad714bd8176a5ea6b81aec65535c2f7aa Mon Sep 17 00:00:00 2001 From: Martin Grisard Date: Sun, 22 Nov 2020 15:35:46 +0100 Subject: [PATCH 2/2] delete png files only if http get was successful delete png files only if http get was successful --- node_helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node_helper.js b/node_helper.js index 272118a..e744a6d 100644 --- a/node_helper.js +++ b/node_helper.js @@ -18,10 +18,10 @@ module.exports = NodeHelper.create({ host: payload.domain, path: payload.path }; - var pngFiles = payload.mmDir + 'modules/mmm-weatherchart/cache/*.png'; - del.sync([pngFiles]); http.get(options, function (response) { + var pngFiles = payload.mmDir + 'modules/mmm-weatherchart/cache/*.png'; + del.sync([pngFiles]); var cachedFile = 'modules/mmm-weatherchart/cache/map-' + new Date().getTime() + '.png'; var newImage = fs.createWriteStream(payload.mmDir + cachedFile);