rubberguppe/net/validators.js

28 lines
768 B
JavaScript
Raw Normal View History

2019-09-21 21:20:14 +00:00
const pub = require('../pub')
module.exports.activity = function activity (req, res, next) {
if (!pub.utils.validateActivity(req.body)) {
2019-09-22 05:20:37 +00:00
return res.status(400).send('Invalid activity')
}
next()
}
module.exports.outboxActivity = function outboxActivity (req, res, next) {
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')
}
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
}
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()
}