start a new fediverse experience

This commit is contained in:
lesion 2019-07-28 20:49:39 +02:00
parent f1d54c776f
commit 37895087c0
4 changed files with 39 additions and 31 deletions

View file

@ -8,7 +8,7 @@ const settingsController = require('./settings')
const get = require('lodash/get')
const botController = {
bot: null,
bots: null,
async initialize() {
const access_token = get(settingsController.secretSettings, 'mastodon_auth.access_token')
const instance = get(settingsController.settings, 'mastodon_instance')

View file

@ -79,38 +79,38 @@ const settingsController = {
res.json(settings)
},
async getAuthURL(req, res) {
const instance = req.body.instance
const callback = `${config.baseurl}/api/settings/oauth`
const { client_id, client_secret } = await Mastodon.createOAuthApp(`https://${instance}/api/v1/apps`,
'gancio', 'read write', callback)
const url = await Mastodon.getAuthorizationUrl(client_id, client_secret,
`https://${instance}`, 'read write', callback)
// async getAuthURL(req, res) {
// const instance = req.body.instance
// const callback = `${config.baseurl}/api/settings/oauth`
// const { client_id, client_secret } = await Mastodon.createOAuthApp(`https://${instance}/api/v1/apps`,
// 'gancio', 'read write', callback)
// const url = await Mastodon.getAuthorizationUrl(client_id, client_secret,
// `https://${instance}`, 'read write', callback)
await settingsController.set('mastodon_instance', instance )
await settingsController.set('mastodon_auth', { client_id, client_secret }, true)
res.json(url)
},
// await settingsController.set('mastodon_instance', instance )
// await settingsController.set('mastodon_auth', { client_id, client_secret }, true)
// res.json(url)
// },
async code(req, res) {
const code = req.query.code
const callback = `${config.baseurl}/api/settings/oauth`
const client_id = settingsController.secretSettings.mastodon_auth.client_id
const client_secret = settingsController.secretSettings.mastodon_auth.client_secret
const instance = settingsController.settings.mastodon_instance
// async code(req, res) {
// const code = req.query.code
// const callback = `${config.baseurl}/api/settings/oauth`
// const client_id = settingsController.secretSettings.mastodon_auth.client_id
// const client_secret = settingsController.secretSettings.mastodon_auth.client_secret
// const instance = settingsController.settings.mastodon_instance
try {
const access_token = await Mastodon.getAccessToken(client_id, client_secret, code,
`https://${instance}`, callback)
const mastodon_auth = { client_id, client_secret, access_token }
await settingsController.set('mastodon_auth', mastodon_auth, true)
const botController = require('./bot')
botController.initialize()
res.redirect('/admin')
} catch (e) {
res.json(e)
}
},
// try {
// const access_token = await Mastodon.getAccessToken(client_id, client_secret, code,
// `https://${instance}`, callback)
// const mastodon_auth = { client_id, client_secret, access_token }
// await settingsController.set('mastodon_auth', mastodon_auth, true)
// const botController = require('./fediverse')
// botController.initialize()
// res.redirect('/admin')
// } catch (e) {
// res.json(e)
// }
// },
}
setTimeout(settingsController.initialize, 200)

View file

@ -3,6 +3,13 @@ const bcrypt = require('bcryptjs')
module.exports = (sequelize, DataTypes) => {
const user = sequelize.define('user', {
username: {
type: DataTypes.STRING,
unique: true,
index: true,
allowNull: false
},
display_name: DataTypes.STRING,
email: {
type: DataTypes.STRING,
unique: true,

View file

@ -1,5 +1,5 @@
const mail = require('./api/mail')
const bot = require('./api/controller/bot')
const bot = require('./api/controller/fediverse')
const settingsController = require('./api/controller/settings')
const config = require('config')
const eventController = require('./api/controller/event')
@ -10,6 +10,7 @@ const { event: Event, notification: Notification, event_notification: EventNoti
const notifier = {
async sendNotification(notification, event) {
return
const promises = []
switch (notification.type) {
case 'mail':