20 lines
494 B
JavaScript
20 lines
494 B
JavaScript
|
const { Middleware, HTTPError } = require('libflitter')
|
||
|
|
||
|
class SettingMiddleware extends Middleware {
|
||
|
static get services() {
|
||
|
return [...super.services, 'models']
|
||
|
}
|
||
|
|
||
|
async test(req, res, next, { key, value = true }) {
|
||
|
const Setting = this.models.get('Setting')
|
||
|
const actual_value = await Setting.get(key)
|
||
|
|
||
|
if ( actual_value !== value )
|
||
|
throw new HTTPError(404)
|
||
|
|
||
|
return next()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = exports = SettingMiddleware
|