linting & cleaning
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
el-main
|
el-main#add_event
|
||||||
h4 <nuxt-link to='/'><img src='/favicon.ico'/></nuxt-link> {{edit?$t('common.edit_event'):$t('common.add_event')}}
|
h4 <nuxt-link to='/'><img src='/favicon.ico'/></nuxt-link> {{edit?$t('common.edit_event'):$t('common.add_event')}}
|
||||||
el-form(v-loading='loading')
|
el-form(v-loading='loading')
|
||||||
client-only
|
client-only
|
||||||
@@ -423,6 +423,10 @@ export default {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
|
#add_event {
|
||||||
|
max-width: 800px;
|
||||||
|
}
|
||||||
|
|
||||||
#picker {
|
#picker {
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
copyLink () {
|
copyLink () {
|
||||||
Message({ message: this.$t('common.copied'), type: 'success' })
|
Message({ message: this.$t('common.copied'), type: 'success', showClose: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import Vue from 'vue'
|
|||||||
import VueI18n from 'vue-i18n'
|
import VueI18n from 'vue-i18n'
|
||||||
import merge from 'lodash/merge'
|
import merge from 'lodash/merge'
|
||||||
import messages from '../locales'
|
import messages from '../locales'
|
||||||
// import acceptLanguage from 'accept-language'
|
|
||||||
|
|
||||||
Vue.use(VueI18n)
|
Vue.use(VueI18n)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ const debug = require('debug')('controller:event')
|
|||||||
|
|
||||||
const eventController = {
|
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) {
|
async addComment (req, res) {
|
||||||
// comments could be added to an event or to another comment
|
// comments could be added to an event or to another comment
|
||||||
let event = await Event.findOne({ where: { activitypub_id: { [Op.eq]: req.body.id } } })
|
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) {
|
async confirm (req, res) {
|
||||||
const id = Number(req.params.event_id)
|
const id = Number(req.params.event_id)
|
||||||
const event = await Event.findByPk(id)
|
const event = await Event.findByPk(id)
|
||||||
@@ -154,6 +160,7 @@ const eventController = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** get all unconfirmed events */
|
||||||
async getUnconfirmed (req, res) {
|
async getUnconfirmed (req, res) {
|
||||||
const events = await Event.findAll({
|
const events = await Event.findAll({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ const config = require('config')
|
|||||||
const consola = require('consola')
|
const consola = require('consola')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const package = require('../../../package.json')
|
const pkg = require('../../../package.json')
|
||||||
|
const debug = require('debug')('settings')
|
||||||
/**
|
/**
|
||||||
* Settings controller: store instance settings
|
* Settings controller: store instance settings
|
||||||
* Current supported settings:
|
* Current supported settings:
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* Usage:
|
* Usage:
|
||||||
* backend/fediverse/api:
|
* backend/fediverse/api:
|
||||||
*
|
*
|
||||||
@@ -23,13 +22,12 @@ const settingsController = {
|
|||||||
|
|
||||||
async initialize () {
|
async initialize () {
|
||||||
if (!settingsController.settings.initialized) {
|
if (!settingsController.settings.initialized) {
|
||||||
|
|
||||||
// initialize instance settings from db
|
// initialize instance settings from db
|
||||||
// note that this is done only once when the server starts
|
// note that this is done only once when the server starts
|
||||||
// and not for each request (it's a kind of cache)!
|
// and not for each request (it's a kind of cache)!
|
||||||
const settings = await Setting.findAll()
|
const settings = await Setting.findAll()
|
||||||
settingsController.settings.initialized = true
|
settingsController.settings.initialized = true
|
||||||
settings.forEach( s => {
|
settings.forEach(s => {
|
||||||
if (s.is_secret) {
|
if (s.is_secret) {
|
||||||
settingsController.secretSettings[s.key] = s.value
|
settingsController.secretSettings[s.key] = s.value
|
||||||
} else {
|
} else {
|
||||||
@@ -38,64 +36,65 @@ const settingsController = {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// set fediverse admin actor
|
// 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) {
|
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
|
// // initialize user_locale
|
||||||
if (config.user_locale && fs.existsSync(path.resolve(config.user_locale))) {
|
if (config.user_locale && fs.existsSync(path.resolve(config.user_locale))) {
|
||||||
const user_locale = fs.readdirSync(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}`)
|
consola.info(`Loading user locale ${f}`)
|
||||||
const locale = path.basename(f, '.js')
|
const locale = path.basename(f, '.js')
|
||||||
settingsController.user_locale[locale] =
|
settingsController.user_locale[locale] =
|
||||||
(await require(path.resolve(config.user_locale, f))).default
|
(await require(path.resolve(config.user_locale, f))).default
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async set(key, value, is_secret=false) {
|
async set (key, value, is_secret = false) {
|
||||||
try {
|
try {
|
||||||
await Setting.findOrCreate({
|
await Setting.findOrCreate({
|
||||||
where: { key },
|
where: { key },
|
||||||
defaults: { value, is_secret }
|
defaults: { value, is_secret }
|
||||||
}).spread((setting, created) => {
|
}).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
|
return true
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getUserLocale(req, res) {
|
getUserLocale (req, res) {
|
||||||
// load user locale specified in configuration
|
// load user locale specified in configuration
|
||||||
res.json(settingsController.user_locale)
|
res.json(settingsController.user_locale)
|
||||||
},
|
},
|
||||||
|
|
||||||
async setRequest(req, res) {
|
async setRequest (req, res) {
|
||||||
const { key, value, is_secret } = req.body
|
const { key, value, is_secret } = req.body
|
||||||
const ret = await settingsController.set(key, value, is_secret)
|
const ret = await settingsController.set(key, value, is_secret)
|
||||||
if (ret) res.sendStatus(200)
|
if (ret) { res.sendStatus(200) } else { res.sendStatus(400) }
|
||||||
else res.sendStatus(400)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getAllRequest(req, res) {
|
getAllRequest (req, res) {
|
||||||
// get public settings and public configuration
|
// get public settings and public configuration
|
||||||
const settings = {
|
const settings = {
|
||||||
...settingsController.settings,
|
...settingsController.settings,
|
||||||
baseurl: config.baseurl,
|
baseurl: config.baseurl,
|
||||||
title: config.title,
|
title: config.title,
|
||||||
description: config.description,
|
description: config.description,
|
||||||
version: package.version
|
version: pkg.version
|
||||||
}
|
}
|
||||||
res.json(settings)
|
res.json(settings)
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsController.initialize()
|
settingsController.initialize()
|
||||||
|
|||||||
@@ -121,8 +121,8 @@ const userController = {
|
|||||||
// send notification (mastodon/email)
|
// send notification (mastodon/email)
|
||||||
// only if user is authenticated
|
// only if user is authenticated
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
const notifier = require('../../notifier')
|
const notifier = require('../../notifier')
|
||||||
notifier.notifyEvent('Create', event.id)
|
notifier.notifyEvent('Create', event.id)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
138
server/cli.js
138
server/cli.js
@@ -3,9 +3,9 @@ process.env.NODE_ENV = 'production'
|
|||||||
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const consola = require('consola')
|
const consola = require('consola')
|
||||||
const sequelize = require('sequelize')
|
const Sequelize = require('sequelize')
|
||||||
const inquirer = require('inquirer')
|
const inquirer = require('inquirer')
|
||||||
const package = require('../package.json')
|
const pkg = require('../package.json')
|
||||||
const firstrun = require('./firstrun')
|
const firstrun = require('./firstrun')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const mkdirp = require('mkdirp')
|
const mkdirp = require('mkdirp')
|
||||||
@@ -17,11 +17,10 @@ const cwd = process.cwd()
|
|||||||
process.chdir(path.resolve(__dirname, '..'))
|
process.chdir(path.resolve(__dirname, '..'))
|
||||||
|
|
||||||
function notEmpty (value) {
|
function notEmpty (value) {
|
||||||
return value.length>0
|
return value.length > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupQuestionnaire(is_docker, db) {
|
async function setupQuestionnaire (is_docker, db) {
|
||||||
|
|
||||||
const questions = []
|
const questions = []
|
||||||
questions.push({
|
questions.push({
|
||||||
name: 'title',
|
name: 'title',
|
||||||
@@ -31,11 +30,14 @@ async function setupQuestionnaire(is_docker, db) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
questions.push({
|
questions.push({
|
||||||
message: 'Specify a baseurl for this gancio installation! (eg. http://gancio.cisti.org)',
|
message:
|
||||||
|
'Specify a baseurl for this gancio installation! (eg. http://gancio.cisti.org)',
|
||||||
name: 'baseurl',
|
name: 'baseurl',
|
||||||
default: 'http://localhost:13120',
|
default: 'http://localhost:13120',
|
||||||
validate: value => {
|
validate: value => {
|
||||||
if (!value) return false
|
if (!value) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return /^https?:\/\//.test(value)
|
return /^https?:\/\//.test(value)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -51,7 +53,7 @@ async function setupQuestionnaire(is_docker, db) {
|
|||||||
questions.push({
|
questions.push({
|
||||||
name: 'server.port',
|
name: 'server.port',
|
||||||
message: 'port to listen to',
|
message: 'port to listen to',
|
||||||
default: 13120,
|
default: 13120
|
||||||
})
|
})
|
||||||
|
|
||||||
questions.push({
|
questions.push({
|
||||||
@@ -67,7 +69,8 @@ async function setupQuestionnaire(is_docker, db) {
|
|||||||
default: './db.sqlite',
|
default: './db.sqlite',
|
||||||
filter: p => path.resolve(cwd, p),
|
filter: p => path.resolve(cwd, p),
|
||||||
when: answers => answers.db.dialect === 'sqlite',
|
when: answers => answers.db.dialect === 'sqlite',
|
||||||
validate: db_path => db_path.length>0 && fs.existsSync(path.dirname(db_path))
|
validate: db_path =>
|
||||||
|
db_path.length > 0 && fs.existsSync(path.dirname(db_path))
|
||||||
})
|
})
|
||||||
|
|
||||||
questions.push({
|
questions.push({
|
||||||
@@ -100,14 +103,19 @@ async function setupQuestionnaire(is_docker, db) {
|
|||||||
message: 'DB password',
|
message: 'DB password',
|
||||||
default: 'gancio',
|
default: 'gancio',
|
||||||
when: answers => answers.db.dialect === 'postgres',
|
when: answers => answers.db.dialect === 'postgres',
|
||||||
validate: async (password, options) => {
|
validate: (password, options) => {
|
||||||
try {
|
try {
|
||||||
const db = new sequelize({ ...options.db, dialect: 'postgres' , password, logging: false })
|
const db = new Sequelize({
|
||||||
return db.authenticate().then( () => {
|
...options.db,
|
||||||
|
dialect: 'postgres',
|
||||||
|
password,
|
||||||
|
logging: false
|
||||||
|
})
|
||||||
|
return db.authenticate().then(() => {
|
||||||
db.close()
|
db.close()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
consola.error(e)
|
consola.error(e)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -119,13 +127,13 @@ async function setupQuestionnaire(is_docker, db) {
|
|||||||
message: 'Where gancio has to store media?',
|
message: 'Where gancio has to store media?',
|
||||||
default: './uploads',
|
default: './uploads',
|
||||||
filter: p => path.resolve(cwd, p),
|
filter: p => path.resolve(cwd, p),
|
||||||
validate: async p => {
|
validate: p => {
|
||||||
let exists = fs.existsSync(p)
|
const exists = fs.existsSync(p)
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
consola.warn(`"${p}" does not exists, trying to create it`)
|
consola.warn(`"${p}" does not exists, trying to create it`)
|
||||||
try {
|
try {
|
||||||
mkdirp.sync(p)
|
mkdirp.sync(p)
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
console.error(String(e))
|
console.error(String(e))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -138,7 +146,10 @@ async function setupQuestionnaire(is_docker, db) {
|
|||||||
name: 'admin.email',
|
name: 'admin.email',
|
||||||
message: `Admin email (a first user with this username will be created)`,
|
message: `Admin email (a first user with this username will be created)`,
|
||||||
default: options => {
|
default: options => {
|
||||||
return options.title.replace(' ', '').toLowerCase() + '@' + url.parse(options.baseurl, true).hostname
|
const baseurl = new url.URL(options.baseurl, true)
|
||||||
|
return (
|
||||||
|
options.title.replace(' ', '').toLowerCase() + '@' + baseurl.hostname
|
||||||
|
)
|
||||||
},
|
},
|
||||||
validate: notEmpty
|
validate: notEmpty
|
||||||
})
|
})
|
||||||
@@ -153,7 +164,7 @@ async function setupQuestionnaire(is_docker, db) {
|
|||||||
questions.push({
|
questions.push({
|
||||||
name: 'smtp.host',
|
name: 'smtp.host',
|
||||||
message: 'SMTP Host',
|
message: 'SMTP Host',
|
||||||
validate: notEmpty,
|
validate: notEmpty
|
||||||
})
|
})
|
||||||
|
|
||||||
questions.push({
|
questions.push({
|
||||||
@@ -167,18 +178,23 @@ async function setupQuestionnaire(is_docker, db) {
|
|||||||
name: 'smtp.auth.pass',
|
name: 'smtp.auth.pass',
|
||||||
message: 'SMTP Password',
|
message: 'SMTP Password',
|
||||||
type: 'password',
|
type: 'password',
|
||||||
validate: notEmpty,
|
validate: notEmpty
|
||||||
})
|
})
|
||||||
|
|
||||||
const answers = await inquirer.prompt(questions)
|
const answers = await inquirer.prompt(questions)
|
||||||
if (is_docker) {
|
if (is_docker) {
|
||||||
answers.server = { host: '0.0.0.0', port: 13120 }
|
answers.server = { host: '0.0.0.0', port: 13120 }
|
||||||
answers.upload_path = '/opt/gancio/uploads'
|
answers.upload_path = '/opt/gancio/uploads'
|
||||||
if(db === 'sqlite') {
|
if (db === 'sqlite') {
|
||||||
answers.db = { dialect: db, storage: '/opt/gancio/db.sqlite' }
|
answers.db = { dialect: db, storage: '/opt/gancio/db.sqlite' }
|
||||||
} else {
|
} else {
|
||||||
answers.db = { dialect: db, host: 'db', database: 'gancio',
|
answers.db = {
|
||||||
username: 'gancio', password: 'gancio'}
|
dialect: db,
|
||||||
|
host: 'db',
|
||||||
|
database: 'gancio',
|
||||||
|
username: 'gancio',
|
||||||
|
password: 'gancio'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,21 +211,26 @@ async function run_migrations (db_conf) {
|
|||||||
logging: consola.info,
|
logging: consola.info,
|
||||||
migrations: {
|
migrations: {
|
||||||
wrap: fun => {
|
wrap: fun => {
|
||||||
return () => fun(db.queryInterface, Sequelize).catch(e => { consola.error(e); return false; })
|
return () =>
|
||||||
},
|
fun(db.queryInterface, Sequelize).catch(e => {
|
||||||
path: path.resolve(__dirname, 'migrations')
|
consola.error(e)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
path: path.resolve(__dirname, 'migrations')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
await umzug.up()
|
await umzug.up()
|
||||||
return await db.close()
|
return db.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function start (options) {
|
async function start (options) {
|
||||||
// is first run?
|
// is first run?
|
||||||
if (firstrun.check(options.config)) {
|
if (firstrun.check(options.config)) {
|
||||||
if (options.docker) {
|
if (options.docker) {
|
||||||
consola.error('⚠ ️ Something goes wrong, did you run "docker-compose run --rm gancio gancio setup"')
|
consola.error(
|
||||||
|
'⚠ ️ Something goes wrong, did you run "docker-compose run --rm gancio gancio setup"'
|
||||||
|
)
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
}
|
}
|
||||||
consola.error(` ⚠ Configuration file "${options.config}" not found! Use "--config <CONFIG_FILE.json>" to specify another path.
|
consola.error(` ⚠ Configuration file "${options.config}" not found! Use "--config <CONFIG_FILE.json>" to specify another path.
|
||||||
@@ -226,43 +247,46 @@ async function setup (options) {
|
|||||||
const config = await setupQuestionnaire(options.docker, options.db)
|
const config = await setupQuestionnaire(options.docker, options.db)
|
||||||
await run_migrations(config.db)
|
await run_migrations(config.db)
|
||||||
const ret = await firstrun.setup(config, options.config)
|
const ret = await firstrun.setup(config, options.config)
|
||||||
if (!ret) process.exit(-1)
|
if (!ret) {
|
||||||
|
process.exit(-1)
|
||||||
|
}
|
||||||
if (options.docker) {
|
if (options.docker) {
|
||||||
consola.info(`You can edit ./config.json to modify your configuration.`)
|
consola.info(`You can edit ./config.json to modify your configuration.`)
|
||||||
consola.info(`Start the server with "docker-compose up"`)
|
consola.info(`Start the server with "docker-compose up"`)
|
||||||
} else {
|
} else {
|
||||||
consola.info(`You can edit '${options.config}' to modify your configuration. `)
|
consola.info(
|
||||||
|
`You can edit '${options.config}' to modify your configuration. `
|
||||||
|
)
|
||||||
consola.info(`Start the server with "gancio --config ${options.config}"`)
|
consola.info(`Start the server with "gancio --config ${options.config}"`)
|
||||||
}
|
}
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
consola.info(`${package.name} - v${package.version} - ${package.description}`)
|
consola.info(`📅 ${pkg.name} - v${pkg.version} - ${pkg.description}`)
|
||||||
|
|
||||||
require('yargs')
|
require('yargs')
|
||||||
.usage('Usage $0 <command> [options]')
|
.usage('Usage $0 <command> [options]')
|
||||||
.option('docker', {
|
.option('docker', {
|
||||||
alias: 'd',
|
alias: 'd',
|
||||||
describe: 'Inside docker',
|
describe: 'Inside docker',
|
||||||
default: false,
|
default: false,
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
})
|
})
|
||||||
.option('db', {
|
.option('db', {
|
||||||
describe: 'Specify db type',
|
describe: 'Specify db type'
|
||||||
})
|
})
|
||||||
.option('config', {
|
.option('config', {
|
||||||
alias: 'c',
|
alias: 'c',
|
||||||
describe: 'Configuration file',
|
describe: 'Configuration file',
|
||||||
default: '/opt/gancio/config.json',
|
default: '/opt/gancio/config.json'
|
||||||
})
|
})
|
||||||
.coerce('config', config_path => {
|
.coerce('config', config_path => {
|
||||||
const absolute_config_path = path.resolve(cwd, config_path)
|
const absolute_config_path = path.resolve(cwd, config_path)
|
||||||
process.env.config_path = absolute_config_path
|
process.env.config_path = absolute_config_path
|
||||||
return absolute_config_path
|
return absolute_config_path
|
||||||
})
|
})
|
||||||
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
|
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
|
||||||
.command('setup', 'Setup a new instance', {}, setup)
|
.command('setup', 'Setup a new instance', {}, setup)
|
||||||
.help('h')
|
.help('h')
|
||||||
.alias('h', 'help')
|
.alias('h', 'help')
|
||||||
.epilog('Made with ❤ by underscore hacklab - https://gancio.org')
|
.epilog('Made with ❤ by underscore hacklab - https://gancio.org')
|
||||||
.argv
|
|
||||||
|
|||||||
Reference in New Issue
Block a user