diff options
| author | Pitu <[email protected]> | 2021-03-23 22:35:29 +0900 |
|---|---|---|
| committer | Pitu <[email protected]> | 2021-03-23 22:35:29 +0900 |
| commit | 541bfedb924ba80f126236656713f769c2194ef2 (patch) | |
| tree | 654876d29f1929b50ff9a19080e87db043bde471 /src/api/utils | |
| parent | Merge branch 'feature/database_based_settings' of https://github.com/Zephyrru... (diff) | |
| download | host.fuwn.me-541bfedb924ba80f126236656713f769c2194ef2.tar.xz host.fuwn.me-541bfedb924ba80f126236656713f769c2194ef2.zip | |
wip
Diffstat (limited to 'src/api/utils')
| -rw-r--r-- | src/api/utils/Util.js | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/api/utils/Util.js b/src/api/utils/Util.js index 6feedd4..b60fca3 100644 --- a/src/api/utils/Util.js +++ b/src/api/utils/Util.js @@ -15,10 +15,30 @@ const StatsGenerator = require('./StatsGenerator'); const blockedExtensions = process.env.BLOCKED_EXTENSIONS.split(','); const preserveExtensions = ['.tar.gz', '.tar.z', '.tar.bz2', '.tar.lzma', '.tar.lzo', '.tar.xz']; -let statsLastSavedTime = null; - class Util { static uploadPath = path.join(__dirname, '../../../', process.env.UPLOAD_FOLDER); + static statsLastSavedTime = null; + static _config = null; + + static get config() { + return (async () => { + if (this._config === null) { + const conf = await db('config').select('key', 'value'); + this._config = conf.reduce((acc, { key, value }) => { + if (typeof value === 'string' || value instanceof String) { + acc[key] = JSON.parse(value); + } else { + acc[key] = value; + } + }, {}); + } + return this._config; + })(); + } + + static invalidateConfigCache() { + this._config = null; + } static uuid() { return uuidv4(); @@ -320,7 +340,7 @@ class Util { // skip generating and saving new stats. if (!force && (!db.userParams.lastMutationTime || - (statsLastSavedTime && statsLastSavedTime > db.userParams.lastMutationTime) + (Util.statsLastSavedTime && Util.statsLastSavedTime > db.userParams.lastMutationTime) ) ) { return; @@ -341,7 +361,7 @@ class Util { await db.table('statistics').insert({ type, data: JSON.stringify(data), createdAt: now, batchId }); } - statsLastSavedTime = now.getTime(); + Util.statsLastSavedTime = now.getTime(); } catch (error) { console.error(error); } |