This commit is contained in:
les
2019-09-11 19:12:24 +02:00
parent 93baf01a55
commit 2fe956d117
65 changed files with 762 additions and 721 deletions

View File

@@ -6,18 +6,30 @@ const settingsController = require('../api/controller/settings')
const config = require('config')
const version = require('../../package.json').version
const url = require('url')
const debug = require('debug')('webfinger')
router.use(cors())
router.get('/webfinger', async (req, res) => {
const resource = req.query.resource
if (!resource || !resource.includes('acct:')) {
debug('Bad webfinger request => %s', resource.query)
return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.')
}
const name = resource.match(/acct:(.*)@/)[1]
const domain = url.parse(config.baseurl).host
const user = await User.findOne({where: { username: name } })
if (!user) return res.status(404).send(`No record found for ${name}`)
const [, name, req_domain] = resource.match(/acct:(.*)@(.*)/)
if (domain !== req_domain) {
debug('Bad webfinger request, requested domain "%s" instead of "%s"', req_domain, domain)
return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.')
}
const user = await User.findOne({ where: { username: name } })
if (!user) {
debug('User not found: %s', name)
return res.status(404).send(`No record found for ${name}`)
}
const ret = {
subject: `acct:${name}@${domain}`,
links: [
@@ -38,24 +50,24 @@ router.get('/nodeinfo/:nodeinfo_version', async (req, res) => {
nodeDescription: 'Gancio instance',
nodeName: config.title
},
openRegistrations : settingsController.settings.allow_registration,
protocols :['activitypub'],
services: { inbound: [], outbound :["atom1.0"]},
openRegistrations: settingsController.settings.allow_registration,
protocols: ['activitypub'],
services: { inbound: [], outbound: ['atom1.0'] },
software: {
name: 'gancio',
version
},
usage: {
usage: {
localComments: 0,
localPosts:0,
localPosts: 0,
users: {
total:3
total: 3
}
},
version: req.params.nodeinfo_version
}
if(req.params.nodeinfo_version === '2.1') {
if (req.params.nodeinfo_version === '2.1') {
ret.software.repository = 'https://git.lattuga.net/cisti/gancio'
}
res.json(ret)
@@ -72,7 +84,7 @@ router.get('/x-nodeinfo2', async (req, res) => {
},
protocols: ['activitypub'],
openRegistrations: settingsController.settings.allow_registration,
usage:{
usage: {
users: {
total: 10
}
@@ -83,18 +95,16 @@ router.get('/x-nodeinfo2', async (req, res) => {
res.json(ret)
})
router.get('/nodeinfo', async (req, res) => {
const ret = {
links: [
{ href: `${config.baseurl}/.well-known/nodeinfo/2.0`, rel: `http://nodeinfo.diaspora.software/ns/schema/2.0` },
{ href: `${config.baseurl}/.well-known/nodeinfo/2.1`, rel: `http://nodeinfo.diaspora.software/ns/schema/2.1` },
{ href: `${config.baseurl}/.well-known/nodeinfo/2.1`, rel: `http://nodeinfo.diaspora.software/ns/schema/2.1` }
]
}
res.json(ret)
})
router.use('/host-meta', (req, res) => {
res.type('application/xml')
res.send(`<?xml version="1.0" encoding="UTF-8"?>
@@ -104,12 +114,14 @@ router.use('/host-meta', (req, res) => {
})
// Handle 404
router.use(function(req, res) {
router.use((req, res) => {
debug('404 Page not found: %s', req.path)
res.status(404).send('404: Page not Found')
})
// Handle 500
router.use(function(error, req, res, next) {
router.use((error, req, res, next) => {
debug(error)
res.status(500).send('500: Internal Server Error')
})