2020-05-18 02:13:38 +00:00
|
|
|
const { Unit } = require('libflitter')
|
|
|
|
|
|
|
|
class SettingsUnit extends Unit {
|
|
|
|
static get name() {
|
|
|
|
return 'settings'
|
|
|
|
}
|
|
|
|
|
|
|
|
static get services() {
|
|
|
|
return [...super.services, 'configs', 'models', 'output']
|
|
|
|
}
|
|
|
|
|
|
|
|
async go(app) {
|
2020-07-12 21:05:59 +00:00
|
|
|
app.express.set('trust proxy', true)
|
|
|
|
|
2020-05-18 02:13:38 +00:00
|
|
|
const Setting = this.models.get('Setting')
|
|
|
|
const default_settings = this.configs.get('setting.settings')
|
|
|
|
for ( const key in default_settings ) {
|
|
|
|
if ( !default_settings.hasOwnProperty(key) ) continue
|
|
|
|
const default_value = default_settings[key]
|
|
|
|
this.output.debug(`Guarantee setting key "${key}" with default value "${default_value}".`)
|
|
|
|
await Setting.guarantee(key, default_value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = SettingsUnit
|