Updated info.js to show deprecation messages when utilizing the options.json. Added translation status to info.js. Implemented the TRANSLATION_HIDDEN_LANGUAGES, TASK_CLEANUP_EXPIRED and TASK_CLEANUP_UNUSED environment variables in variables.js. Updated language dropdown to hide themselves if the number of allowed languages is lower than 2. Added the created at field within details.ejs. Implemented cleanup.js for automatically cleaning-up expired and unused vouchers. Updated the languages.js util with global filters. Added country flags to languages.js. Updated docker-compose.yml. Dependency updates. Updated README.md. Lowered log intensity within server.js

This commit is contained in:
Glenn de Haan
2025-08-26 18:21:30 +02:00
parent f36fa1144a
commit 7af385c8fe
14 changed files with 332 additions and 188 deletions

69
utils/cleanup.js Normal file
View File

@@ -0,0 +1,69 @@
/**
* Import own modules
*/
const cache = require('../modules/cache');
const log = require('../modules/log');
const unifi = require('../modules/unifi');
/**
* Import own utils
*/
const {updateCache} = require('./cache');
module.exports = {
/**
* Function to clean up expired vouchers
*
* @returns {Promise<unknown>}
*/
cleanupExpired: () => {
return new Promise(async (resolve) => {
// Filter vouchers in cache
const vouchers = cache.vouchers.filter((voucher) => {
return voucher.expired;
});
log.debug(`[Cleanup] Removing ${vouchers.length} voucher(s)...`);
// Remove vouchers
for(let item = 0; item < vouchers.length; item++) {
log.debug(`[Cleanup] Removing voucher: ${vouchers[item].id}`);
await unifi.remove(vouchers[item].id);
}
// Update cache
await updateCache();
resolve();
});
},
/**
* Function to clean up unused voucher that are still active after a day
*
* @returns {Promise<unknown>}
*/
cleanupUnused: () => {
return new Promise(async (resolve) => {
const vouchers = cache.vouchers.filter((voucher) => {
const today = new Date();
const voucherDate = new Date(voucher.createdAt);
voucherDate.setDate(voucherDate.getDate() + 1);
return voucherDate.getTime() < today.getTime();
});
log.debug(`[Cleanup] Removing ${vouchers.length} voucher(s)...`);
for(let item = 0; item < vouchers.length; item++) {
log.debug(`[Cleanup] Removing voucher: ${vouchers[item].id}...`);
await unifi.remove(vouchers[item].id);
}
// Update cache
await updateCache();
resolve();
});
}
}