got followers
This commit is contained in:
@@ -1,69 +1,68 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const moment = require('moment')
|
||||
const { event: Event, comment: Comment } = require('../models')
|
||||
const config = require('config')
|
||||
const Mastodon = require('mastodon-api')
|
||||
const settingsController = require('./settings')
|
||||
const get = require('lodash/get')
|
||||
// const fs = require('fs')
|
||||
// const path = require('path')
|
||||
// const moment = require('moment')
|
||||
// const { event: Event, comment: Comment } = require('../models')
|
||||
// const config = require('config')
|
||||
// const settingsController = require('./settings')
|
||||
// const get = require('lodash/get')
|
||||
|
||||
const botController = {
|
||||
bots: null,
|
||||
async initialize() {
|
||||
const access_token = get(settingsController.secretSettings, 'mastodon_auth.access_token')
|
||||
const instance = get(settingsController.settings, 'mastodon_instance')
|
||||
if (!access_token || !instance) return
|
||||
botController.bot = new Mastodon({
|
||||
access_token,
|
||||
api_url: `https://${instance}/api/v1`
|
||||
})
|
||||
const listener = botController.bot.stream('/streaming/user')
|
||||
listener.on('message', botController.message)
|
||||
listener.on('error', botController.error)
|
||||
},
|
||||
async post(event) {
|
||||
const status = `${event.title} @${event.place.name} ${moment(event.start_datetime).format('ddd, D MMMM HH:mm')} -
|
||||
${event.description.length > 200 ? event.description.substr(0, 200) + '...' : event.description} - ${event.tags.map(t => '#' + t.tag).join(' ')} ${config.baseurl}/event/${event.id}`
|
||||
// const botController = {
|
||||
// bots: null,
|
||||
// async initialize() {
|
||||
// const access_token = get(settingsController.secretSettings, 'mastodon_auth.access_token')
|
||||
// const instance = get(settingsController.settings, 'mastodon_instance')
|
||||
// if (!access_token || !instance) return
|
||||
// botController.bot = new Mastodon({
|
||||
// access_token,
|
||||
// api_url: `https://${instance}/api/v1`
|
||||
// })
|
||||
// const listener = botController.bot.stream('/streaming/user')
|
||||
// listener.on('message', botController.message)
|
||||
// listener.on('error', botController.error)
|
||||
// },
|
||||
// async post(event) {
|
||||
// const status = `${event.title} @${event.place.name} ${moment(event.start_datetime).format('ddd, D MMMM HH:mm')} -
|
||||
// ${event.description.length > 200 ? event.description.substr(0, 200) + '...' : event.description} - ${event.tags.map(t => '#' + t.tag).join(' ')} ${config.baseurl}/event/${event.id}`
|
||||
|
||||
let media
|
||||
if (event.image_path) {
|
||||
const file = path.resolve(config.upload_path, event.image_path)
|
||||
if (fs.statSync(file)) {
|
||||
media = await botController.bot.post('/media', { file: fs.createReadStream(file) })
|
||||
}
|
||||
}
|
||||
return botController.bot.post('/statuses', { status, media_ids: media ? [media.data.id] : [] })
|
||||
},
|
||||
// let media
|
||||
// if (event.image_path) {
|
||||
// const file = path.resolve(config.upload_path, event.image_path)
|
||||
// if (fs.statSync(file)) {
|
||||
// media = await botController.bot.post('/media', { file: fs.createReadStream(file) })
|
||||
// }
|
||||
// }
|
||||
// return botController.bot.post('/statuses', { status, media_ids: media ? [media.data.id] : [] })
|
||||
// },
|
||||
|
||||
async message(msg) {
|
||||
const type = msg.event
|
||||
// async message(msg) {
|
||||
// const type = msg.event
|
||||
|
||||
if (type === 'delete') {
|
||||
const activitypub_id = String(msg.data)
|
||||
const event = await Comment.findOne({ where: { activitypub_id } })
|
||||
if (event) await event.destroy()
|
||||
return
|
||||
}
|
||||
// if (type === 'delete') {
|
||||
// const activitypub_id = String(msg.data)
|
||||
// const event = await Comment.findOne({ where: { activitypub_id } })
|
||||
// if (event) await event.destroy()
|
||||
// return
|
||||
// }
|
||||
|
||||
const activitypub_id = String(msg.data.status.in_reply_to_id)
|
||||
if (!activitypub_id) return
|
||||
let event = await Event.findOne({ where: { activitypub_id } })
|
||||
if (!event) {
|
||||
// check for comment..
|
||||
const comment = await Comment.findOne( { include: [Event], where: { activitypub_id }})
|
||||
if (!comment) return
|
||||
event = comment.event
|
||||
}
|
||||
await Comment.create({
|
||||
activitypub_id: String(msg.data.status.id),
|
||||
data: msg.data.status,
|
||||
eventId: event.id
|
||||
})
|
||||
},
|
||||
error(err) {
|
||||
console.log('error ', err)
|
||||
}
|
||||
}
|
||||
// const activitypub_id = String(msg.data.status.in_reply_to_id)
|
||||
// if (!activitypub_id) return
|
||||
// let event = await Event.findOne({ where: { activitypub_id } })
|
||||
// if (!event) {
|
||||
// // check for comment..
|
||||
// const comment = await Comment.findOne( { include: [Event], where: { activitypub_id }})
|
||||
// if (!comment) return
|
||||
// event = comment.event
|
||||
// }
|
||||
// await Comment.create({
|
||||
// activitypub_id: String(msg.data.status.id),
|
||||
// data: msg.data.status,
|
||||
// eventId: event.id
|
||||
// })
|
||||
// },
|
||||
// error(err) {
|
||||
// console.log('error ', err)
|
||||
// }
|
||||
// }
|
||||
|
||||
setTimeout(botController.initialize, 5000)
|
||||
module.exports = botController
|
||||
// setTimeout(botController.initialize, 5000)
|
||||
// module.exports = botController
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
const Mastodon = require('mastodon-api')
|
||||
const { setting: Setting } = require('../models')
|
||||
const config = require('config')
|
||||
const consola = require('consola')
|
||||
@@ -78,39 +77,6 @@ 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)
|
||||
|
||||
// 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
|
||||
|
||||
// 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)
|
||||
|
||||
@@ -21,14 +21,15 @@ fs
|
||||
const model = sequelize.import(path.join(__dirname, file))
|
||||
db[model.name] = model
|
||||
})
|
||||
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db)
|
||||
}
|
||||
})
|
||||
|
||||
db.sequelize = sequelize
|
||||
db.Sequelize = Sequelize
|
||||
|
||||
module.exports = db
|
||||
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db)
|
||||
}
|
||||
})
|
||||
|
||||
db.sequelize = sequelize
|
||||
db.Sequelize = Sequelize
|
||||
|
||||
module.exports = db
|
||||
|
||||
@@ -25,7 +25,11 @@ module.exports = (sequelize, DataTypes) => {
|
||||
recover_code: DataTypes.STRING,
|
||||
is_admin: DataTypes.BOOLEAN,
|
||||
is_active: DataTypes.BOOLEAN,
|
||||
rsa: DataTypes.JSONB
|
||||
rsa: DataTypes.JSON,
|
||||
followers: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: []
|
||||
}
|
||||
}, {
|
||||
scopes: {
|
||||
withoutPassword: {
|
||||
|
||||
Reference in New Issue
Block a user