2018-09-15 07:01:19 +00:00
|
|
|
'use strict';
|
|
|
|
const express = require('express'),
|
|
|
|
router = express.Router();
|
2019-09-13 01:03:04 +00:00
|
|
|
// const inbox = require('./inbox');
|
|
|
|
const {toJSONLD} = require('../utils/index.js');
|
2018-09-15 07:01:19 +00:00
|
|
|
|
2019-09-13 01:03:04 +00:00
|
|
|
router.get('/:name', async function (req, res) {
|
2018-09-15 07:01:19 +00:00
|
|
|
let name = req.params.name;
|
|
|
|
if (!name) {
|
|
|
|
return res.status(400).send('Bad request.');
|
|
|
|
}
|
|
|
|
else {
|
2019-09-13 01:03:04 +00:00
|
|
|
let objs = req.app.get('objs');
|
|
|
|
const id = `https://${req.app.get('domain')}/u/${name}`
|
|
|
|
console.log(`looking up '${id}'`)
|
|
|
|
const user = await objs.findOne({type: 'Person', id: id}, {fields: {_id: 0}})
|
|
|
|
// .project({_id: 0})
|
|
|
|
if (user) {
|
|
|
|
return res.json(toJSONLD(user))
|
2019-03-26 05:17:24 +00:00
|
|
|
}
|
2019-09-13 01:03:04 +00:00
|
|
|
return res.status(404).send('Person not found')
|
2018-09-15 07:01:19 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-13 01:03:04 +00:00
|
|
|
// router.get('/:name/followers', function (req, res) {
|
|
|
|
// let name = req.params.name;
|
|
|
|
// if (!name) {
|
|
|
|
// return res.status(400).send('Bad request.');
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// let db = req.app.get('db');
|
|
|
|
// let domain = req.app.get('domain');
|
|
|
|
// let result = db.prepare('select followers from accounts where name = ?').get(`${name}@${domain}`);
|
|
|
|
// console.log(result);
|
|
|
|
// result.followers = result.followers || '[]';
|
|
|
|
// let followers = JSON.parse(result.followers);
|
|
|
|
// let followersCollection = {
|
|
|
|
// "type":"OrderedCollection",
|
|
|
|
// "totalItems":followers.length,
|
|
|
|
// "id":`https://${domain}/u/${name}/followers`,
|
|
|
|
// "first": {
|
|
|
|
// "type":"OrderedCollectionPage",
|
|
|
|
// "totalItems":followers.length,
|
|
|
|
// "partOf":`https://${domain}/u/${name}/followers`,
|
|
|
|
// "orderedItems": followers,
|
|
|
|
// "id":`https://${domain}/u/${name}/followers?page=1`
|
|
|
|
// },
|
|
|
|
// "@context":["https://www.w3.org/ns/activitystreams"]
|
|
|
|
// };
|
|
|
|
// res.json(toJSONLD(followersCollection));
|
|
|
|
// }
|
|
|
|
// });
|
2019-03-26 04:26:17 +00:00
|
|
|
|
2018-09-15 07:01:19 +00:00
|
|
|
module.exports = router;
|