[refactor] remove username field and let instance_name be the only AP Actor
This commit is contained in:
@@ -5,6 +5,22 @@ const path = require('path')
|
||||
const fs = require('fs')
|
||||
const pkg = require('../../../package.json')
|
||||
const debug = require('debug')('settings')
|
||||
const crypto = require('crypto')
|
||||
const util = require('util')
|
||||
const generateKeyPair = util.promisify(crypto.generateKeyPair)
|
||||
|
||||
const defaultSettings = {
|
||||
instance_timezone: 'Europe/Rome',
|
||||
instance_name: config.title.toLowerCase().replace(/ /g, ''),
|
||||
allow_registration: true,
|
||||
allow_anon_event: true,
|
||||
allow_recurrent_event: false,
|
||||
recurrent_event_visible: false,
|
||||
enable_federation: true,
|
||||
enable_resources: false,
|
||||
hide_boosts: true
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings controller: store instance settings
|
||||
* Current supported settings:
|
||||
@@ -20,13 +36,14 @@ const settingsController = {
|
||||
user_locale: {},
|
||||
secretSettings: {},
|
||||
|
||||
async initialize () {
|
||||
async load () {
|
||||
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
|
||||
settingsController.settings = defaultSettings
|
||||
settings.forEach(s => {
|
||||
if (s.is_secret) {
|
||||
settingsController.secretSettings[s.key] = s.value
|
||||
@@ -35,16 +52,26 @@ const settingsController = {
|
||||
}
|
||||
})
|
||||
|
||||
// set fediverse admin actor
|
||||
const fedi_admin = await User.findOne({ where: { email: config.admin_email } })
|
||||
if (fedi_admin) {
|
||||
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
|
||||
// add pub/priv instance key if needed
|
||||
if (!settingsController.settings.publicKey) {
|
||||
debug('Instance priv/pub key not found')
|
||||
const { publicKey, privateKey } = await generateKeyPair('rsa', {
|
||||
modulusLength: 4096,
|
||||
publicKeyEncoding: {
|
||||
type: 'spki',
|
||||
format: 'pem'
|
||||
},
|
||||
privateKeyEncoding: {
|
||||
type: 'pkcs8',
|
||||
format: 'pem'
|
||||
}
|
||||
})
|
||||
|
||||
await settingsController.set('publicKey', publicKey)
|
||||
await settingsController.set('privateKey', privateKey, true)
|
||||
}
|
||||
|
||||
// // initialize user_locale
|
||||
// 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 => {
|
||||
@@ -97,5 +124,5 @@ const settingsController = {
|
||||
}
|
||||
}
|
||||
|
||||
settingsController.initialize()
|
||||
// settingsController.initialize()
|
||||
module.exports = settingsController
|
||||
|
||||
Reference in New Issue
Block a user