refactorin docker files

This commit is contained in:
les
2019-09-25 14:38:16 +02:00
parent 803a217122
commit d2f08d3412
9 changed files with 24 additions and 46 deletions

View File

@@ -11,6 +11,7 @@ const settingsController = require('./settings')
const federation = require('../../federation/helpers')
const util = require('util')
const generateKeyPair = util.promisify(crypto.generateKeyPair)
const debug = require('debug')('user:controller')
const userController = {
async login (req, res) {
@@ -237,22 +238,6 @@ const userController = {
if (!req.body.password) { delete req.body.password }
// generate an rsa key in case not present
if (!user.rsa) {
const rsa = await generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem'
}
})
req.body.rsa = rsa
}
await user.update(req.body)
if (!user.is_active && req.body.is_active && user.recover_code) {

View File

@@ -65,7 +65,7 @@ async function setupQuestionnaire(is_docker, db) {
message: 'sqlite db path',
default: is_docker ? '/opt/gancio/db.sqlite' : './db.sqlite',
filter: p => path.resolve(cwd, p),
when: answers => (db && db==='sqlite') || (answers.db && answers.db.dialect === 'sqlite'),
when: answers => ((db && db==='sqlite') || (answers.db && answers.db.dialect === 'sqlite')) && !is_docker,
validate: db_path => db_path.length>0 && fs.existsSync(path.dirname(db_path))
})
@@ -73,7 +73,7 @@ async function setupQuestionnaire(is_docker, db) {
name: 'db.host',
message: 'Postgres host',
default: is_docker ? 'db' : 'localhost',
when: answers => (db && db==='postgresql') || (answers.db && answers.db.dialect === 'postgres'),
when: answers => ((db && db==='postgresql') || (answers.db && answers.db.dialect === 'postgres')) && !is_docker,
validate: notEmpty
})

View File

@@ -6,7 +6,7 @@ const httpSignature = require('http-signature')
const debug = require('debug')('federation:helpers')
const { user: User, fed_users: FedUsers } = require('../api/models')
const url = require('url')
const settings = require('../api/controller/settings')
const settingsController = require('../api/controller/settings')
const Helpers = {
@@ -53,12 +53,11 @@ const Helpers = {
},
async sendEvent (event, user) {
if (!settings.settings.enable_federation) {
if (!settingsController.settings.enable_federation) {
debug('event not send, federation disabled')
return
}
// event is sent by user that published it and by the admin instance
// collect followers from admin and user
const instanceAdmin = await User.findOne({ where: { email: config.admin_email }, include: { model: FedUsers, as: 'followers' } })
@@ -128,15 +127,6 @@ const Helpers = {
},
// DO NOT USE THIS! (why is this needed btw?)
// async getFederatedUser (address) {
// address = address.trim()
// const [ username, host ] = address.split('@')
// const url = `https://${host}/.well-known/webfinger?resource=acct:${username}@${host}`
// return Helpers.getActor(url)
// },
// TODO: cache
async getActor (url, force = false) {
let fedi_user

View File

@@ -4,6 +4,7 @@ const cors = require('cors')
const Follows = require('./follows')
const Users = require('./users')
const { event: Event, user: User, tag: Tag, place: Place } = require('../api/models')
const settingsController = require('../api/controller/settings')
const Comments = require('./comments')
const Helpers = require('./helpers')
const Ego = require('./ego')
@@ -14,6 +15,11 @@ const debug = require('debug')('federation')
* ref: https://www.w3.org/TR/activitypub/#Overview
*/
router.use((req, res, next) => {
if(settingsController.settings.enable_federation) next()
debug('Federation disabled!')
return res.status(401).send('Federation disabled')
})
router.use(cors())
router.use(express.json({ type: ['application/json', 'application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'] }))