2019-09-21 21:53:55 +00:00
|
|
|
'use strict'
|
|
|
|
const express = require('express')
|
|
|
|
const router = express.Router()
|
|
|
|
|
2019-09-22 05:05:30 +00:00
|
|
|
const pub = require('../pub')
|
2019-09-15 00:00:26 +00:00
|
|
|
const acctReg = /acct:[@~]?([^@]+)@?(.*)/
|
2018-09-15 07:01:19 +00:00
|
|
|
router.get('/', function (req, res) {
|
2019-09-22 05:20:37 +00:00
|
|
|
const resource = req.query.resource
|
|
|
|
const acct = acctReg.exec(resource)
|
2019-09-15 00:00:26 +00:00
|
|
|
if (!acct || acct.length < 2) {
|
2019-09-22 05:20:37 +00:00
|
|
|
return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.')
|
2018-09-15 07:01:19 +00:00
|
|
|
}
|
2019-09-15 00:00:26 +00:00
|
|
|
if (acct[2] && acct[2].toLowerCase() !== req.app.get('domain').toLowerCase()) {
|
|
|
|
return res.status(400).send('Requested user is not from this domain')
|
2018-09-15 07:01:19 +00:00
|
|
|
}
|
2019-09-22 05:20:37 +00:00
|
|
|
const db = req.app.get('db')
|
2019-09-22 05:05:30 +00:00
|
|
|
pub.actor.getOrCreateActor(acct[1], db)
|
2019-09-15 00:00:26 +00:00
|
|
|
.then(result => {
|
|
|
|
if (!result) {
|
|
|
|
return res.status(404).send(`${acct[1]}@${acct[2]} not found`)
|
|
|
|
}
|
|
|
|
const finger = {
|
2019-09-22 05:20:37 +00:00
|
|
|
subject: resource,
|
|
|
|
links: [
|
2019-09-15 00:00:26 +00:00
|
|
|
{
|
2019-09-22 05:20:37 +00:00
|
|
|
rel: 'self',
|
|
|
|
type: 'application/activity+json',
|
|
|
|
href: result.id
|
2019-09-15 00:00:26 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
return res.json(finger)
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2019-09-22 05:20:37 +00:00
|
|
|
console.log(err)
|
2019-09-15 00:00:26 +00:00
|
|
|
res.status(500).send()
|
|
|
|
})
|
2019-09-22 05:20:37 +00:00
|
|
|
})
|
2018-09-15 07:01:19 +00:00
|
|
|
|
2019-09-22 05:20:37 +00:00
|
|
|
module.exports = router
|