You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
822 B
JavaScript
37 lines
822 B
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
const WebFinger = require("webfinger.js");
|
|
const url = require("url");
|
|
|
|
let webfinger = Promise.promisifyAll(new WebFinger());
|
|
|
|
module.exports = function lookupUser(address) {
|
|
return Promise.try(() => {
|
|
return webfinger.lookupAsync(address);
|
|
}).then((response) => {
|
|
let aliasCount = response?.object?.aliases?.length;
|
|
|
|
if (aliasCount == null || aliasCount === 0) {
|
|
return {};
|
|
} else {
|
|
let { hostname, port } = url.parse(response.object.aliases[0]);
|
|
|
|
return {
|
|
aliases: response.object.aliases,
|
|
hostname: hostname,
|
|
apiURL: url.format({
|
|
protocol: "https",
|
|
slashes: true,
|
|
hostname: hostname,
|
|
port: port,
|
|
pathname: "/api/v1/instance"
|
|
})
|
|
};
|
|
}
|
|
}).catch((error) => {
|
|
console.log({error});
|
|
return {};
|
|
});
|
|
};
|