From c9637524ec8d51902561b747515f0616000e2bb9 Mon Sep 17 00:00:00 2001 From: teddit Date: Sat, 27 Nov 2021 14:57:38 +0100 Subject: [PATCH] set cache_control_interval in hours instead of milliseconds --- README.md | 2 +- cacheControl.js | 12 ++++++++---- config.js.template | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1467955..59de368 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ The following variables may be set to customize your deployment at runtime. | reddit_app_id | If "use_reddit_oauth" config key is set to true, you have to obtain your Reddit app ID. For testing purposes it's okay to use this project's default app ID. Create your Reddit app here: https://old.reddit.com/prefs/apps/. Make sure to create an "installed app" type of app. Default is **ABfYqdDc9qPh1w** | | domain_replacements | Replacements for domains in outgoing links. Tuples with regular expressions to match, and replacement values. This is in addition to user-level configuration of privacyDomains. Defaults to **[]** | | cache_control | *Boolean* If true, teddit will automatically remove all cached static files. Defaults to **true** | -| cache_control_interval | How often the cache directory for static files is emptied (in milliseconds). Default is every 24 hours. Requires cache_control to be true. Defaults to **1000 * 60 * 60 * 24** | +| cache_control_interval | How often the cache directory for static files is emptied (in hours). Default is every 24 hours. Requires cache_control to be true. Defaults to **24** | ### Manual diff --git a/cacheControl.js b/cacheControl.js index 4893a75..522daca 100644 --- a/cacheControl.js +++ b/cacheControl.js @@ -5,7 +5,7 @@ module.exports.removeCacheFiles = function() { 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}`) @@ -19,10 +19,14 @@ module.exports.removeCacheFiles = function() { if(config.cache_control) { deleteStatic(); - - const interval_ms = config.cache_control_interval + + const hours = config.cache_control_interval; + if (hours < 1 || isNaN(hours)) { + hours = 24; + } + setInterval(() => { deleteStatic(); - }, interval_ms); + }, 1000 * 60 * 60 * hours); } } diff --git a/config.js.template b/config.js.template index 58a554e..62ebb56 100644 --- a/config.js.template +++ b/config.js.template @@ -33,7 +33,7 @@ const config = { ? (JSON.parse(process.env.DOMAIN_REPLACEMENTS).map(([p, r]) => [new RegExp(p, 'gm'), r])) : [], // Replacements for domains in outgoing links. Tuples with regular expressions to match, and replacement values. This is in addition to user-level configuration of privacyDomains. cache_control: process.env.CACHE_CONTROL !== 'true' || true, // If true, teddit will automatically remove all cached static files. By default this is set to true. - cache_control_interval: process.env.CACHE_CONTROL_INTERVAL || 1000 * 60 * 60 * 24, // How often the cache directory for static files is emptied (in milliseconds). Requires cache_control to be true. Default is every 24 hours. + cache_control_interval: process.env.CACHE_CONTROL_INTERVAL || 24, // How often the cache directory for static files is emptied (in hours). Requires cache_control to be true. Default is every 24 hours. post_media_max_heights: { /** * Sets the max-height value for images and videos in posts.