mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-04-05 08:53:53 -04:00
Refactored unifi.js to separate logic. Updated application header. Fixed incorrect screen-reader text. Updated sync button text. Implemented last sync date/time. Implemented cache util. Fixed missing vouchers check to prevent 'headers are already send' error. Fixed missing cache sync on api voucher creation. Implemented auto sync every 15 minutes
This commit is contained in:
37
utils/cache.js
Normal file
37
utils/cache.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Import own modules
|
||||
*/
|
||||
const log = require('../modules/log');
|
||||
const unifi = require('../modules/unifi');
|
||||
const cache = require('../modules/cache');
|
||||
|
||||
/**
|
||||
* Exports all cache utils
|
||||
*
|
||||
* @type {{updateCache: (function(): Promise<*>)}}
|
||||
*/
|
||||
module.exports = {
|
||||
/**
|
||||
* Update the cache
|
||||
*
|
||||
* @return {Promise<*>}
|
||||
*/
|
||||
updateCache: () => {
|
||||
return new Promise(async (resolve) => {
|
||||
log.info('[Cache] Requesting UniFi Vouchers...');
|
||||
|
||||
const vouchers = await unifi.list().catch((e) => {
|
||||
log.error('[Cache] Error requesting vouchers!');
|
||||
log.error(e);
|
||||
});
|
||||
|
||||
if(vouchers) {
|
||||
cache.vouchers = vouchers;
|
||||
cache.updated = new Date().getTime();
|
||||
log.info(`[Cache] Saved ${vouchers.length} voucher(s)`);
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user