linting & cleaning

This commit is contained in:
les
2019-11-06 11:31:56 +01:00
parent d8f6ae2e49
commit 64654748d5
7 changed files with 121 additions and 88 deletions

View File

@@ -1,5 +1,5 @@
<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')}}
el-form(v-loading='loading')
client-only
@@ -423,6 +423,10 @@ export default {
}
</script>
<style>
#add_event {
max-width: 800px;
}
#picker {
max-width: 400px;
}

View File

@@ -25,7 +25,7 @@ export default {
},
methods: {
copyLink () {
Message({ message: this.$t('common.copied'), type: 'success' })
Message({ message: this.$t('common.copied'), type: 'success', showClose: true })
}
}
}

View File

@@ -2,7 +2,6 @@ import Vue from 'vue'
import VueI18n from 'vue-i18n'
import merge from 'lodash/merge'
import messages from '../locales'
// import acceptLanguage from 'accept-language'
Vue.use(VueI18n)

View File

@@ -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: {

View File

@@ -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()

View File

@@ -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)
}
},

View File

@@ -3,9 +3,9 @@ process.env.NODE_ENV = 'production'
const fs = require('fs')
const consola = require('consola')
const sequelize = require('sequelize')
const Sequelize = require('sequelize')
const inquirer = require('inquirer')
const package = require('../package.json')
const pkg = require('../package.json')
const firstrun = require('./firstrun')
const path = require('path')
const mkdirp = require('mkdirp')
@@ -17,11 +17,10 @@ const cwd = process.cwd()
process.chdir(path.resolve(__dirname, '..'))
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 = []
questions.push({
name: 'title',
@@ -31,11 +30,14 @@ async function setupQuestionnaire(is_docker, db) {
})
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',
default: 'http://localhost:13120',
validate: value => {
if (!value) return false
if (!value) {
return false
}
return /^https?:\/\//.test(value)
}
})
@@ -51,7 +53,7 @@ async function setupQuestionnaire(is_docker, db) {
questions.push({
name: 'server.port',
message: 'port to listen to',
default: 13120,
default: 13120
})
questions.push({
@@ -67,7 +69,8 @@ async function setupQuestionnaire(is_docker, db) {
default: './db.sqlite',
filter: p => path.resolve(cwd, p),
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({
@@ -85,7 +88,7 @@ async function setupQuestionnaire(is_docker, db) {
when: answers => answers.db.dialect === 'postgres',
validate: notEmpty
})
questions.push({
name: 'db.username',
message: 'DB user',
@@ -93,21 +96,26 @@ async function setupQuestionnaire(is_docker, db) {
when: answers => answers.db.dialect === 'postgres',
validate: notEmpty
})
questions.push({
name: 'db.password',
type: 'password',
message: 'DB password',
default: 'gancio',
when: answers => answers.db.dialect === 'postgres',
validate: async (password, options) => {
validate: (password, options) => {
try {
const db = new sequelize({ ...options.db, dialect: 'postgres' , password, logging: false })
return db.authenticate().then( () => {
const db = new Sequelize({
...options.db,
dialect: 'postgres',
password,
logging: false
})
return db.authenticate().then(() => {
db.close()
return true
})
} catch(e) {
} catch (e) {
consola.error(e)
return false
}
@@ -119,13 +127,13 @@ async function setupQuestionnaire(is_docker, db) {
message: 'Where gancio has to store media?',
default: './uploads',
filter: p => path.resolve(cwd, p),
validate: async p => {
let exists = fs.existsSync(p)
validate: p => {
const exists = fs.existsSync(p)
if (!exists) {
consola.warn(`"${p}" does not exists, trying to create it`)
try {
mkdirp.sync(p)
} catch(e) {
} catch (e) {
console.error(String(e))
return false
}
@@ -138,11 +146,14 @@ async function setupQuestionnaire(is_docker, db) {
name: 'admin.email',
message: `Admin email (a first user with this username will be created)`,
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
})
questions.push({
name: 'admin.password',
message: 'Admin password',
@@ -153,7 +164,7 @@ async function setupQuestionnaire(is_docker, db) {
questions.push({
name: 'smtp.host',
message: 'SMTP Host',
validate: notEmpty,
validate: notEmpty
})
questions.push({
@@ -167,18 +178,23 @@ async function setupQuestionnaire(is_docker, db) {
name: 'smtp.auth.pass',
message: 'SMTP Password',
type: 'password',
validate: notEmpty,
validate: notEmpty
})
const answers = await inquirer.prompt(questions)
if (is_docker) {
answers.server = { host: '0.0.0.0', port: 13120 }
answers.upload_path = '/opt/gancio/uploads'
if(db === 'sqlite') {
if (db === 'sqlite') {
answers.db = { dialect: db, storage: '/opt/gancio/db.sqlite' }
} else {
answers.db = { dialect: db, host: 'db', database: 'gancio',
username: 'gancio', password: 'gancio'}
answers.db = {
dialect: db,
host: 'db',
database: 'gancio',
username: 'gancio',
password: 'gancio'
}
}
}
@@ -195,21 +211,26 @@ async function run_migrations (db_conf) {
logging: consola.info,
migrations: {
wrap: fun => {
return () => fun(db.queryInterface, Sequelize).catch(e => { consola.error(e); return false; })
},
path: path.resolve(__dirname, 'migrations')
return () =>
fun(db.queryInterface, Sequelize).catch(e => {
consola.error(e)
return false
})
},
path: path.resolve(__dirname, 'migrations')
}
})
await umzug.up()
return await db.close()
return db.close()
}
async function start (options) {
// is first run?
if (firstrun.check(options.config)) {
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)
}
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)
await run_migrations(config.db)
const ret = await firstrun.setup(config, options.config)
if (!ret) process.exit(-1)
if (!ret) {
process.exit(-1)
}
if (options.docker) {
consola.info(`You can edit ./config.json to modify your configuration.`)
consola.info(`Start the server with "docker-compose up"`)
} 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}"`)
}
process.exit(0)
}
consola.info(`${package.name} - v${package.version} - ${package.description}`)
consola.info(`📅 ${pkg.name} - v${pkg.version} - ${pkg.description}`)
require('yargs')
.usage('Usage $0 <command> [options]')
.option('docker', {
alias: 'd',
describe: 'Inside docker',
default: false,
type: 'boolean'
})
.option('db', {
describe: 'Specify db type',
})
.option('config', {
alias: 'c',
describe: 'Configuration file',
default: '/opt/gancio/config.json',
})
.coerce('config', config_path => {
const absolute_config_path = path.resolve(cwd, config_path)
process.env.config_path = absolute_config_path
return absolute_config_path
})
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
.command('setup', 'Setup a new instance', {}, setup)
.help('h')
.alias('h', 'help')
.epilog('Made with ❤ by underscore hacklab - https://gancio.org')
.argv
.usage('Usage $0 <command> [options]')
.option('docker', {
alias: 'd',
describe: 'Inside docker',
default: false,
type: 'boolean'
})
.option('db', {
describe: 'Specify db type'
})
.option('config', {
alias: 'c',
describe: 'Configuration file',
default: '/opt/gancio/config.json'
})
.coerce('config', config_path => {
const absolute_config_path = path.resolve(cwd, config_path)
process.env.config_path = absolute_config_path
return absolute_config_path
})
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
.command('setup', 'Setup a new instance', {}, setup)
.help('h')
.alias('h', 'help')
.epilog('Made with ❤ by underscore hacklab - https://gancio.org')