Changed watcher to only reload after midnight

This commit is contained in:
MarcUs7i 2025-02-23 00:16:12 +01:00
parent e6edc8c54b
commit 8263dd5f56

View file

@ -13,6 +13,13 @@ watchFile('./config.js', async ()=>{ // Dynamically reload config and watch it f
const statusFile = './static/status.json';
const getMillisUntilMidnight = () => {
const now = new Date();
const midnight = new Date(now);
midnight.setHours(24, 0, 0, 0);
return midnight - now;
}
const delay = async t=>new Promise(r=>setTimeout(r, t));
const handlize = s=>s.toLowerCase().replace(/[^a-z0-9]/g, ' ').trim().replace(/\s+/g, '-');
const checkContent = async (content, criterion, negate=false) => {
@ -332,5 +339,5 @@ while(true) {
console.error(e);
}
config.verbose && console.log('✅ Done');
await delay(config.interval * 60_000 - (Date.now() - startPulse));
await delay(getMillisUntilMidnight());
}