rubberguppe/routes/outbox.js

34 lines
1,002 B
JavaScript
Raw Normal View History

const express = require('express')
const router = express.Router()
2019-09-21 21:20:14 +00:00
const net = require('../net')
const pub = require('../pub')
const store = require('../store')
router.post('/', net.security.auth, net.validators.outboxActivity, function (req, res) {
store.actor.get(pub.utils.usernameToIRI(req.user), true)
.then(actor => {
return pub.activity.addToOutbox(actor, req.body)
})
.then(() => res.status(200).send())
.catch(err => {
2019-10-01 01:55:20 +00:00
console.log(err.message)
res.status(500).send()
})
2019-09-22 05:20:37 +00:00
})
router.get('/', function (req, res) {
2019-09-22 05:20:37 +00:00
const db = req.app.get('db')
db.collection('streams')
2019-09-22 05:20:37 +00:00
.find({ actor: pub.utils.usernameToIRI(req.user) })
.sort({ _id: -1 })
.project({ _id: 0, _meta: 0, 'object._id': 0, 'object.@context': 0, 'object._meta': 0 })
.toArray()
2019-09-21 21:20:14 +00:00
.then(stream => res.json(pub.utils.arrayToCollection(stream, true)))
.catch(err => {
2019-10-01 01:55:20 +00:00
console.log(err.message)
return res.status(500).send()
})
})
2019-09-22 05:20:37 +00:00
module.exports = router