2019-07-30 18:32:26 +02:00
|
|
|
const { user: User } = require('../api/models')
|
|
|
|
const config = require('config')
|
2019-07-30 18:47:17 +02:00
|
|
|
const get = require('lodash/get')
|
2019-07-30 18:32:26 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
async get (req, res) {
|
|
|
|
const name = req.params.name
|
|
|
|
if (!name) return res.status(400).send('Bad request.')
|
|
|
|
const user = await User.findOne({where: { username: name }})
|
|
|
|
if (!user) return res.status(404).send(`No record found for ${name}`)
|
|
|
|
const ret = {
|
|
|
|
'@context': [
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1'
|
|
|
|
],
|
|
|
|
id: `${config.baseurl}/federation/u/${name}`,
|
|
|
|
type: 'Person',
|
|
|
|
preferredUsername: name,
|
|
|
|
nodeInfo2Url: `${config.baseurl}/.well-known/x-nodeinfo2`,
|
|
|
|
inbox: `${config.baseurl}/federation/u/${name}/inbox`,
|
|
|
|
outbox: `${config.baseurl}/federation/u/${name}/outbox`,
|
|
|
|
followers: `${config.baseurl}/federation/u/${name}/followers`,
|
|
|
|
publicKey: {
|
|
|
|
id: `${config.baseurl}/federation/u/${name}#main-key`,
|
|
|
|
owner: `${config.baseurl}/federation/u/${name}`,
|
|
|
|
publicKeyPem: get(user, 'rsa.publicKey', '')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res.json(ret)
|
|
|
|
},
|
|
|
|
async followers (req, res) {
|
|
|
|
const name = req.params.name
|
|
|
|
if (!name) return res.status(400).send('Bad request.')
|
|
|
|
const user = await User.findOne({where: { username: name }})
|
|
|
|
if (!user) return res.status(404).send(`No record found for ${name}`)
|
|
|
|
const ret = {
|
|
|
|
'@context': [ 'https://www.w3.org/ns/activitystreams' ],
|
|
|
|
id: `${config.baseurl}/federation/u/${name}/followers`,
|
|
|
|
type: 'OrderedCollection',
|
|
|
|
totalItems: user.followers.length,
|
|
|
|
first: {
|
|
|
|
id: `${config.baseurl}/federation/u/${name}/followers?page=1`,
|
|
|
|
type: 'OrderedCollectionPage',
|
|
|
|
totalItems: user.followers.length,
|
|
|
|
partOf: `${config.baseurl}/federation/u/${name}/followers`,
|
|
|
|
orderedItems: user.followers,
|
|
|
|
}
|
|
|
|
}
|
2019-07-30 18:53:59 +02:00
|
|
|
res.json(ret)
|
2019-07-30 18:32:26 +02:00
|
|
|
},
|
|
|
|
outbox (req, res) {
|
2019-07-30 18:53:59 +02:00
|
|
|
const name = req.params.name
|
|
|
|
if (!name) return res.status(400).send('Bad request.')
|
2019-07-30 18:32:26 +02:00
|
|
|
console.error('Inside outbox, should return all events from this user')
|
2019-07-30 18:55:05 +02:00
|
|
|
const ret = {
|
2019-07-30 18:53:59 +02:00
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: `${config.baseurl}/federation/u/${name}/outbox`,
|
|
|
|
type: 'OrderedCollection',
|
|
|
|
totalItems: 1,
|
|
|
|
first: {
|
|
|
|
id: `${config.baseurl}/federation/u/${name}/outbox`,
|
|
|
|
type: 'OrderedCollectionPage',
|
|
|
|
orderedItems: [{content: 'ciao'}]
|
|
|
|
}
|
|
|
|
}
|
2019-07-30 18:55:05 +02:00
|
|
|
return res.json(ret)
|
2019-07-30 18:32:26 +02:00
|
|
|
}
|
2019-07-30 18:47:17 +02:00
|
|
|
}
|