feat: ability to view federated profiles via url manipulation

This commit is contained in:
Julian Lam
2023-05-29 17:42:44 -04:00
parent 7e1dac39ea
commit a05b674e27
4 changed files with 95 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
'use strict';
const request = require('request-promise-native');
const Helpers = module.exports;
Helpers.query = async (id) => {
const [username, hostname] = id.split('@');
if (!username || !hostname) {
return false;
}
// Make a webfinger query to retrieve routing information
const response = await request(`https://${hostname}/.well-known/webfinger?resource=acct:${id}`, {
simple: false,
resolveWithFullResponse: true,
json: true,
});
if (response.statusCode !== 200 || !response.body.hasOwnProperty('links')) {
return false;
}
// Parse links to find actor endpoint
let actorUri = response.body.links.filter(link => link.type === 'application/activity+json' && link.rel === 'self');
if (actorUri.length) {
actorUri = actorUri.pop();
({ href: actorUri } = actorUri);
}
return { username, hostname, actorUri };
};