From 1437ec7affe319042cfb3d32bf3e472e6d259608 Mon Sep 17 00:00:00 2001 From: xbdm <114549769+xbdmHQ@users.noreply.github.com> Date: Sun, 24 Nov 2024 14:03:02 -0800 Subject: [PATCH] revert currently not able to test, i forgot to do that instead. not at my regular setup right now so my bad for that! --- src/cache_control.js | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/cache_control.js b/src/cache_control.js index d78f957..5732e63 100644 --- a/src/cache_control.js +++ b/src/cache_control.js @@ -1,29 +1,20 @@ -const fs = require('fs/promises'); // Use promises for better handling -const path = require('path'); -const config = require('../config'); +module.exports.removeCacheFiles = function() { + const config = require('../config'); -async function deleteStatic() { - const wiki_files = path.resolve(__dirname, '../media/wikipedia'); // Resolve relative path + async function deleteStatic() { + const fs = require('fs'); + const wiki_files = './media/wikipedia/'; - try { - await fs.rm(wiki_files, { recursive: true, force: true }); - console.log( - 'Cleared cached static media files. You can turn this off by setting the config.cache_control to false.' - ); - } catch (error) { - console.error(`Error clearing cached static media files: ${error.message}`); + fs.rm(wiki_files, { recursive: true, force: true }, () => { + console.log('Cleared cached static media files. You can turn this off by setting the config.cache_control to false.'); + }); } -} -module.exports.removeCacheFiles = function () { - if (config.cache_control) { + if(config.cache_control) { deleteStatic(); - let hours = parseInt(config.cache_control_interval, 10); - if (isNaN(hours) || hours < 1) { - console.warn( - 'Invalid cache_control_interval. Defaulting to 24 hours.' - ); + let hours = config.cache_control_interval; + if (hours < 1 || isNaN(hours)) { hours = 24; } @@ -31,4 +22,4 @@ module.exports.removeCacheFiles = function () { deleteStatic(); }, 1000 * 60 * 60 * hours); } -}; +}