2021-08-24 17:17:46 +02:00
|
|
|
module.exports.removeCacheFiles = function() {
|
2021-11-26 21:33:12 +01:00
|
|
|
const config = require('./config');
|
2021-08-24 17:17:46 +02:00
|
|
|
|
2021-11-26 21:33:12 +01:00
|
|
|
async function deleteStatic() {
|
2022-01-29 23:53:51 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const pics = './static/pics/';
|
|
|
|
const vids = './static/vids/';
|
2021-11-27 14:57:38 +01:00
|
|
|
|
2022-01-29 23:53:51 +01:00
|
|
|
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 }));
|
2021-11-26 21:33:12 +01:00
|
|
|
|
2022-01-29 23:53:51 +01:00
|
|
|
console.log('Cleared cached static media files. You can turn this off by setting the config.cache_control to false.');
|
2021-11-26 21:33:12 +01:00
|
|
|
});
|
2022-01-29 23:53:51 +01:00
|
|
|
});
|
2021-08-24 17:17:46 +02:00
|
|
|
}
|
|
|
|
|
2021-11-26 21:33:12 +01:00
|
|
|
if(config.cache_control) {
|
|
|
|
deleteStatic();
|
2021-11-27 14:57:38 +01:00
|
|
|
|
2022-01-29 23:53:51 +01:00
|
|
|
let hours = config.cache_control_interval;
|
|
|
|
if (hours < 1 || hours > 10000 || isNaN(hours)) {
|
2021-11-27 14:57:38 +01:00
|
|
|
hours = 24;
|
|
|
|
}
|
|
|
|
|
2021-08-24 17:17:46 +02:00
|
|
|
setInterval(() => {
|
2021-11-26 21:33:12 +01:00
|
|
|
deleteStatic();
|
2021-11-27 14:57:38 +01:00
|
|
|
}, 1000 * 60 * 60 * hours);
|
2021-08-24 17:17:46 +02:00
|
|
|
}
|
|
|
|
}
|