split /inbox fediverse management
This commit is contained in:
48
server/federation/inbox.js
Normal file
48
server/federation/inbox.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
const Follows = require('./follows')
|
||||||
|
const Resources = require('./resources')
|
||||||
|
const Ego = require('./ego')
|
||||||
|
const log = require('../log')
|
||||||
|
|
||||||
|
module.exports = async (req, res) => {
|
||||||
|
const b = req.body
|
||||||
|
log.debug(b.type)
|
||||||
|
switch (b.type) {
|
||||||
|
case 'Follow':
|
||||||
|
Follows.follow(req, res)
|
||||||
|
break
|
||||||
|
case 'Undo':
|
||||||
|
// unfollow || unlike || unboost
|
||||||
|
if (b.object.type === 'Follow') {
|
||||||
|
Follows.unfollow(req, res)
|
||||||
|
} else if (b.object.type === 'Like') {
|
||||||
|
Ego.unbookmark(req, res)
|
||||||
|
} else if (b.object.type === 'Announce') {
|
||||||
|
Ego.unboost(req, res)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'Announce':
|
||||||
|
Ego.boost(req, res)
|
||||||
|
break
|
||||||
|
case 'Note':
|
||||||
|
log.debug('This is a note! I probably should create a comment here')
|
||||||
|
break
|
||||||
|
case 'Like':
|
||||||
|
Ego.bookmark(req, res)
|
||||||
|
break
|
||||||
|
case 'Delete':
|
||||||
|
await Resources.remove(req, res)
|
||||||
|
break
|
||||||
|
case 'Create':
|
||||||
|
// this is a reply
|
||||||
|
if (b.object.type === 'Note') {
|
||||||
|
log.debug('Create a resource!')
|
||||||
|
await Resources.create(req, res)
|
||||||
|
} else if (b.object.type === 'Event') {
|
||||||
|
log.debug('Event type is coming!!')
|
||||||
|
} else {
|
||||||
|
// await Resources.create(req, res)
|
||||||
|
log.warn(`Create with unsupported Object or not a reply => ${b.object.type}`)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
const cors = require('cors')
|
const cors = require('cors')
|
||||||
const Follows = require('./follows')
|
|
||||||
const Users = require('./users')
|
const Users = require('./users')
|
||||||
const Event = require('../api/models/event')
|
const Event = require('../api/models/event')
|
||||||
const User = require('../api/models/user')
|
const User = require('../api/models/user')
|
||||||
@@ -9,10 +8,9 @@ const Tag = require('../api/models/tag')
|
|||||||
const Place = require('../api/models/place')
|
const Place = require('../api/models/place')
|
||||||
|
|
||||||
const settingsController = require('../api/controller/settings')
|
const settingsController = require('../api/controller/settings')
|
||||||
const Resources = require('./resources')
|
|
||||||
const Helpers = require('./helpers')
|
const Helpers = require('./helpers')
|
||||||
const Ego = require('./ego')
|
const Inbox = require('./inbox')
|
||||||
const debug = require('debug')('federation')
|
const log = require('../log')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Federation is calling!
|
* Federation is calling!
|
||||||
@@ -24,7 +22,7 @@ router.use(cors())
|
|||||||
// is federation enabled? middleware
|
// is federation enabled? middleware
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
if (settingsController.settings.enable_federation) { return next() }
|
if (settingsController.settings.enable_federation) { return next() }
|
||||||
debug('Federation disabled!')
|
log.debug('Federation disabled!')
|
||||||
res.status(401).send('Federation disabled')
|
res.status(401).send('Federation disabled')
|
||||||
next(false)
|
next(false)
|
||||||
})
|
})
|
||||||
@@ -32,6 +30,7 @@ router.use((req, res, next) => {
|
|||||||
router.use(express.json({ type: ['application/json', 'application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'] }))
|
router.use(express.json({ type: ['application/json', 'application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'] }))
|
||||||
|
|
||||||
router.get('/m/:event_id', async (req, res) => {
|
router.get('/m/:event_id', async (req, res) => {
|
||||||
|
log.debug('[AP] Get event details ')
|
||||||
const event_id = req.params.event_id
|
const event_id = req.params.event_id
|
||||||
if (req.accepts('html')) { return res.redirect(301, `/event/${event_id}`) }
|
if (req.accepts('html')) { return res.redirect(301, `/event/${event_id}`) }
|
||||||
|
|
||||||
@@ -41,50 +40,7 @@ router.get('/m/:event_id', async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// get any message coming from federation
|
// get any message coming from federation
|
||||||
// Federation is calling!
|
router.post('/u/:name/inbox', Helpers.verifySignature, Inbox)
|
||||||
router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => {
|
|
||||||
const b = req.body
|
|
||||||
debug(b.type)
|
|
||||||
switch (b.type) {
|
|
||||||
case 'Follow':
|
|
||||||
Follows.follow(req, res)
|
|
||||||
break
|
|
||||||
case 'Undo':
|
|
||||||
// unfollow || unlike || unboost
|
|
||||||
if (b.object.type === 'Follow') {
|
|
||||||
Follows.unfollow(req, res)
|
|
||||||
} else if (b.object.type === 'Like') {
|
|
||||||
Ego.unbookmark(req, res)
|
|
||||||
} else if (b.object.type === 'Announce') {
|
|
||||||
Ego.unboost(req, res)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
case 'Announce':
|
|
||||||
Ego.boost(req, res)
|
|
||||||
break
|
|
||||||
case 'Note':
|
|
||||||
debug('This is a note! I probably should create a comment here')
|
|
||||||
break
|
|
||||||
case 'Like':
|
|
||||||
Ego.bookmark(req, res)
|
|
||||||
break
|
|
||||||
case 'Delete':
|
|
||||||
await Resources.remove(req, res)
|
|
||||||
break
|
|
||||||
case 'Create':
|
|
||||||
// this is a reply
|
|
||||||
if (b.object.type === 'Note') {
|
|
||||||
debug('Create a resource!')
|
|
||||||
await Resources.create(req, res)
|
|
||||||
} else if (b.object.type === 'Event') {
|
|
||||||
debug('Event type is coming!!')
|
|
||||||
} else {
|
|
||||||
// await Resources.create(req, res)
|
|
||||||
debug('Create with unsupported Object or not a reply => %s ', b.object.type)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function redirect_on_html_accepted (req, res, next) {
|
function redirect_on_html_accepted (req, res, next) {
|
||||||
if (req.accepts('html')) {
|
if (req.accepts('html')) {
|
||||||
@@ -99,7 +55,7 @@ router.get('/u/:name', redirect_on_html_accepted, Users.get)
|
|||||||
|
|
||||||
// Handle 404
|
// Handle 404
|
||||||
router.use((req, res) => {
|
router.use((req, res) => {
|
||||||
debug('404 Page not found: %s', req.path)
|
log.warn(`404 Page not found: ${req.path}`)
|
||||||
res.status(404).send('404: Page not Found')
|
res.status(404).send('404: Page not Found')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const mail = require('./api/mail')
|
const mail = require('./api/mail')
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
const debug = require('debug')('notifier')
|
const log = require('./log')
|
||||||
const fediverseHelpers = require('./federation/helpers')
|
const fediverseHelpers = require('./federation/helpers')
|
||||||
|
|
||||||
const Event = require('./api/models/event')
|
const Event = require('./api/models/event')
|
||||||
@@ -16,7 +16,7 @@ const notifier = {
|
|||||||
|
|
||||||
sendNotification (notification, event) {
|
sendNotification (notification, event) {
|
||||||
const promises = []
|
const promises = []
|
||||||
debug('Send %s notification %s', notification.type, notification.action)
|
log.debug(`Send ${notification.type} notification ${notification.action}`)
|
||||||
let p
|
let p
|
||||||
switch (notification.type) {
|
switch (notification.type) {
|
||||||
// case 'mail': TODO: locale?
|
// case 'mail': TODO: locale?
|
||||||
@@ -38,7 +38,7 @@ const notifier = {
|
|||||||
include: [Tag, Place, Notification, User]
|
include: [Tag, Place, Notification, User]
|
||||||
})
|
})
|
||||||
|
|
||||||
debug('%s -> %s', action, event.title)
|
log.debug(action, event.title)
|
||||||
|
|
||||||
// insert notifications
|
// insert notifications
|
||||||
const notifications = await eventController.getNotifications(event, action)
|
const notifications = await eventController.getNotifications(event, action)
|
||||||
@@ -51,7 +51,7 @@ const notifier = {
|
|||||||
await notifier.sendNotification(notification, event)
|
await notifier.sendNotification(notification, event)
|
||||||
notification.event_notification.status = 'sent'
|
notification.event_notification.status = 'sent'
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debug(err)
|
log.error(err)
|
||||||
notification.event_notification.status = 'error'
|
notification.event_notification.status = 'error'
|
||||||
}
|
}
|
||||||
return notification.event_notification.save()
|
return notification.event_notification.save()
|
||||||
@@ -71,7 +71,7 @@ const notifier = {
|
|||||||
e.status = 'sent'
|
e.status = 'sent'
|
||||||
return e.save()
|
return e.save()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debug(err)
|
log.error(err)
|
||||||
e.status = 'error'
|
e.status = 'error'
|
||||||
e.error = err
|
e.error = err
|
||||||
return e.save()
|
return e.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user