rubberguppe/routes/webfinger.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

'use strict'
const express = require('express')
const router = express.Router()
const pub = require('../pub')
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)
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
}
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')
pub.actor.getOrCreateActor(acct[1], db)
.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-22 05:20:37 +00:00
rel: 'self',
type: 'application/activity+json',
href: result.id
}
]
}
return res.json(finger)
})
.catch(err => {
2019-09-22 05:20:37 +00:00
console.log(err)
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