linting & cleaning
This commit is contained in:
@@ -10,7 +10,10 @@ const debug = require('debug')('controller:event')
|
||||
|
||||
const eventController = {
|
||||
|
||||
// NOT USED ANYWHERE, comments are added from fediverse, should we remove this?
|
||||
/** add a comment to event
|
||||
* @todo not used anywhere, should we use with webmention?
|
||||
* @todo should we use this for roply coming from fediverse?
|
||||
*/
|
||||
async addComment (req, res) {
|
||||
// comments could be added to an event or to another comment
|
||||
let event = await Event.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } } })
|
||||
@@ -115,6 +118,9 @@ const eventController = {
|
||||
}
|
||||
},
|
||||
|
||||
/** confirm an anonymous event
|
||||
* and send its relative notifications
|
||||
*/
|
||||
async confirm (req, res) {
|
||||
const id = Number(req.params.event_id)
|
||||
const event = await Event.findByPk(id)
|
||||
@@ -154,6 +160,7 @@ const eventController = {
|
||||
}
|
||||
},
|
||||
|
||||
/** get all unconfirmed events */
|
||||
async getUnconfirmed (req, res) {
|
||||
const events = await Event.findAll({
|
||||
where: {
|
||||
|
||||
@@ -3,16 +3,15 @@ const config = require('config')
|
||||
const consola = require('consola')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const package = require('../../../package.json')
|
||||
|
||||
const pkg = require('../../../package.json')
|
||||
const debug = require('debug')('settings')
|
||||
/**
|
||||
* Settings controller: store instance settings
|
||||
* Current supported settings:
|
||||
*
|
||||
*
|
||||
*
|
||||
* Usage:
|
||||
* backend/fediverse/api:
|
||||
*
|
||||
*
|
||||
* frontend:
|
||||
*/
|
||||
|
||||
@@ -23,13 +22,12 @@ const settingsController = {
|
||||
|
||||
async initialize () {
|
||||
if (!settingsController.settings.initialized) {
|
||||
|
||||
// initialize instance settings from db
|
||||
// note that this is done only once when the server starts
|
||||
// and not for each request (it's a kind of cache)!
|
||||
const settings = await Setting.findAll()
|
||||
settingsController.settings.initialized = true
|
||||
settings.forEach( s => {
|
||||
settings.forEach(s => {
|
||||
if (s.is_secret) {
|
||||
settingsController.secretSettings[s.key] = s.value
|
||||
} else {
|
||||
@@ -38,64 +36,65 @@ const settingsController = {
|
||||
})
|
||||
|
||||
// set fediverse admin actor
|
||||
const fedi_admin = await User.findOne({ where: { email: config.admin_email }})
|
||||
const fedi_admin = await User.findOne({ where: { email: config.admin_email } })
|
||||
if (fedi_admin) {
|
||||
settingsController.settings['fedi_admin'] = fedi_admin.username
|
||||
settingsController.settings.fedi_admin = fedi_admin.username
|
||||
} else {
|
||||
debug('Federation disabled! An admin with %s as email cannot be found', config.admin_email)
|
||||
settingsController.settings.enable_federation = false
|
||||
}
|
||||
|
||||
// // initialize user_locale
|
||||
if (config.user_locale && fs.existsSync(path.resolve(config.user_locale))) {
|
||||
const user_locale = fs.readdirSync(path.resolve(config.user_locale))
|
||||
user_locale.forEach( async f => {
|
||||
user_locale.forEach(async f => {
|
||||
consola.info(`Loading user locale ${f}`)
|
||||
const locale = path.basename(f, '.js')
|
||||
settingsController.user_locale[locale] =
|
||||
(await require(path.resolve(config.user_locale, f))).default
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
async set(key, value, is_secret=false) {
|
||||
async set (key, value, is_secret = false) {
|
||||
try {
|
||||
await Setting.findOrCreate({
|
||||
where: { key },
|
||||
defaults: { value, is_secret }
|
||||
}).spread((setting, created) => {
|
||||
if (!created) return setting.update({ value, is_secret })
|
||||
if (!created) { return setting.update({ value, is_secret }) }
|
||||
})
|
||||
settingsController[is_secret?'secretSettings':'settings'][key]=value
|
||||
settingsController[is_secret ? 'secretSettings' : 'settings'][key] = value
|
||||
return true
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
async getUserLocale(req, res) {
|
||||
getUserLocale (req, res) {
|
||||
// load user locale specified in configuration
|
||||
res.json(settingsController.user_locale)
|
||||
},
|
||||
|
||||
async setRequest(req, res) {
|
||||
async setRequest (req, res) {
|
||||
const { key, value, is_secret } = req.body
|
||||
const ret = await settingsController.set(key, value, is_secret)
|
||||
if (ret) res.sendStatus(200)
|
||||
else res.sendStatus(400)
|
||||
if (ret) { res.sendStatus(200) } else { res.sendStatus(400) }
|
||||
},
|
||||
|
||||
getAllRequest(req, res) {
|
||||
getAllRequest (req, res) {
|
||||
// get public settings and public configuration
|
||||
const settings = {
|
||||
...settingsController.settings,
|
||||
baseurl: config.baseurl,
|
||||
title: config.title,
|
||||
description: config.description,
|
||||
version: package.version
|
||||
version: pkg.version
|
||||
}
|
||||
res.json(settings)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
settingsController.initialize()
|
||||
|
||||
@@ -121,8 +121,8 @@ const userController = {
|
||||
// send notification (mastodon/email)
|
||||
// only if user is authenticated
|
||||
if (req.user) {
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Create', event.id)
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Create', event.id)
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user