2019-09-21 21:20:14 +00:00
|
|
|
const pub = require('../pub')
|
2019-09-15 00:00:26 +00:00
|
|
|
|
2019-09-28 03:17:54 +00:00
|
|
|
module.exports = {
|
|
|
|
activity,
|
|
|
|
jsonld,
|
|
|
|
outboxActivity
|
|
|
|
}
|
|
|
|
|
|
|
|
function activity (req, res, next) {
|
2019-09-23 17:52:22 +00:00
|
|
|
if (!pub.utils.validateActivity(req.body)) {
|
2019-09-22 05:20:37 +00:00
|
|
|
return res.status(400).send('Invalid activity')
|
|
|
|
}
|
|
|
|
next()
|
2019-09-15 00:00:26 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 03:17:54 +00:00
|
|
|
function jsonld (req, res, next) {
|
2019-09-28 04:28:12 +00:00
|
|
|
if (req.method === 'GET' && req.accepts(pub.consts.jsonldTypes)) {
|
2019-09-28 03:17:54 +00:00
|
|
|
return next()
|
|
|
|
}
|
2019-09-28 04:28:12 +00:00
|
|
|
if (req.method === 'POST' && req.is(pub.consts.jsonldTypes)) {
|
2019-09-28 03:17:54 +00:00
|
|
|
return next()
|
|
|
|
}
|
|
|
|
next('route')
|
|
|
|
}
|
|
|
|
|
|
|
|
function outboxActivity (req, res, next) {
|
2019-09-23 17:52:22 +00:00
|
|
|
if (!pub.utils.validateActivity(req.body)) {
|
|
|
|
if (!pub.utils.validateObject(req.body)) {
|
2019-09-22 05:20:37 +00:00
|
|
|
return res.status(400).send('Invalid activity')
|
2019-09-15 00:00:26 +00:00
|
|
|
}
|
2019-09-23 17:52:22 +00:00
|
|
|
const actor = pub.utils.usernameToIRI(req.user)
|
|
|
|
const extras = {}
|
|
|
|
if (req.body.bcc) {
|
|
|
|
extras.bcc = req.body.bcc
|
|
|
|
}
|
|
|
|
if (req.body.audience) {
|
|
|
|
extras.audience = req.body.audience
|
2019-09-22 05:20:37 +00:00
|
|
|
}
|
2019-09-23 17:52:22 +00:00
|
|
|
req.body = pub.activity
|
|
|
|
.build('Create', actor, req.body, req.body.to, req.body.cc, extras)
|
2019-09-22 05:20:37 +00:00
|
|
|
}
|
|
|
|
next()
|
|
|
|
}
|