2019-09-15 00:00:26 +00:00
|
|
|
const express = require('express')
|
|
|
|
const router = express.Router()
|
|
|
|
const utils = require('../utils')
|
2019-09-21 21:20:14 +00:00
|
|
|
const net = require('../net')
|
|
|
|
const pub = require('../pub')
|
2019-09-15 00:00:26 +00:00
|
|
|
|
2019-09-21 21:20:14 +00:00
|
|
|
router.post('/', net.validators.outboxActivity, function (req, res) {
|
2019-09-15 00:00:26 +00:00
|
|
|
const db = req.app.get('db');
|
|
|
|
Promise.all([
|
|
|
|
db.collection('objects').insertOne(req.body.object),
|
|
|
|
db.collection('streams').insertOne(req.body)
|
|
|
|
]).then(() => res.status(200).send())
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
res.status(500).send()
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/', function (req, res) {
|
|
|
|
const db = req.app.get('db');
|
|
|
|
db.collection('streams')
|
2019-09-21 21:20:14 +00:00
|
|
|
.find({actor: pub.utils.usernameToIRI(req.user)})
|
2019-09-15 00:00:26 +00:00
|
|
|
.sort({_id: -1})
|
2019-09-20 01:55:32 +00:00
|
|
|
.project({_id: 0, _meta: 0, 'object._id': 0, 'object.@context': 0, 'object._meta': 0})
|
2019-09-15 00:00:26 +00:00
|
|
|
.toArray()
|
2019-09-21 21:20:14 +00:00
|
|
|
.then(stream => res.json(pub.utils.arrayToCollection(stream, true)))
|
2019-09-15 00:00:26 +00:00
|
|
|
.catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
return res.status(500).send()
|
|
|
|
})
|
|
|
|
;
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = router;
|