From 265c33fcd2817af466aca6b612040ac05a0e48bb Mon Sep 17 00:00:00 2001 From: teddit Date: Sat, 29 Jan 2022 23:53:51 +0100 Subject: [PATCH] use 24 hours interval if the interval value (config.cache_control_interval) is set to over 1000. fixes cache control for older config.cache_control_interval values --- cacheControl.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cacheControl.js b/cacheControl.js index 522daca..a4c3fc6 100644 --- a/cacheControl.js +++ b/cacheControl.js @@ -2,26 +2,26 @@ module.exports.removeCacheFiles = function() { const config = require('./config'); async function deleteStatic() { - const fs = require('fs'); - const pics = './static/pics/'; - const vids = './static/vids/'; + const fs = require('fs'); + const pics = './static/pics/'; + const vids = './static/vids/'; - fs.rmdir(pics, { recursive: true, force: true }, () => { - fs.rmdir(vids, { recursive: true, force: true }, () => { - ['pics/thumbs', 'pics/flairs', 'pics/icons', 'vids'].map((d) => `./static/${d}`) - .filter((d) => !fs.existsSync(d)) - .forEach((d) => fs.mkdirSync(d, { recursive: true })); + fs.rmdir(pics, { recursive: true, force: true }, () => { + fs.rmdir(vids, { recursive: true, force: true }, () => { + ['pics/thumbs', 'pics/flairs', 'pics/icons', 'vids'].map((d) => `./static/${d}`) + .filter((d) => !fs.existsSync(d)) + .forEach((d) => fs.mkdirSync(d, { recursive: true })); - console.log('Cleared cached static media files. You can turn this off by setting the config.cache_control to false.'); - }); + console.log('Cleared cached static media files. You can turn this off by setting the config.cache_control to false.'); }); + }); } if(config.cache_control) { deleteStatic(); - const hours = config.cache_control_interval; - if (hours < 1 || isNaN(hours)) { + let hours = config.cache_control_interval; + if (hours < 1 || hours > 10000 || isNaN(hours)) { hours = 24; }