42 lines
1 KiB
JavaScript
42 lines
1 KiB
JavaScript
'use strict'
|
|
const express = require('express')
|
|
const router = express.Router()
|
|
const pub = require('../pub')
|
|
|
|
router.get('/:name', async function (req, res) {
|
|
const name = req.params.name
|
|
if (!name) {
|
|
return res.status(400).send('Bad request.')
|
|
} else {
|
|
const user = await pub.actor.getOrCreateActor(name)
|
|
if (user) {
|
|
return res.json(pub.utils.toJSONLD(user))
|
|
}
|
|
return res.status(404).send('Person not found')
|
|
}
|
|
})
|
|
|
|
router.get('/:name/followers', function (req, res) {
|
|
const name = req.params.name
|
|
if (!name) {
|
|
return res.status(400).send('Bad request.')
|
|
}
|
|
const db = req.app.get('db')
|
|
db.collection('streams')
|
|
.find({
|
|
type: 'Follow',
|
|
'_meta._target': pub.utils.usernameToIRI(name)
|
|
})
|
|
.project({ _id: 0, actor: 1 })
|
|
.toArray()
|
|
.then(follows => {
|
|
const followers = follows.map(pub.utils.actorFromActivity)
|
|
return res.json(pub.utils.arrayToCollection(followers))
|
|
})
|
|
.catch(err => {
|
|
console.log(err)
|
|
return res.status(500).send()
|
|
})
|
|
})
|
|
|
|
module.exports = router
|