mirror of
https://github.com/hotomoe/hotomoe
synced 2024-12-13 22:28:14 +09:00
d3c0f3c251
* requestをnode-fetchになど * format * fix error * t * Fix test
34 lines
794 B
TypeScript
34 lines
794 B
TypeScript
import { getJson } from '../misc/fetch';
|
|
import { query as urlQuery } from '../prelude/url';
|
|
|
|
type ILink = {
|
|
href: string;
|
|
rel?: string;
|
|
};
|
|
|
|
type IWebFinger = {
|
|
links: ILink[];
|
|
subject: string;
|
|
};
|
|
|
|
export default async function(query: string): Promise<IWebFinger> {
|
|
const url = genUrl(query);
|
|
|
|
return await getJson(url, 'application/jrd+json, application/json');
|
|
}
|
|
|
|
function genUrl(query: string) {
|
|
if (query.match(/^https?:\/\//)) {
|
|
const u = new URL(query);
|
|
return `${u.protocol}//${u.hostname}/.well-known/webfinger?` + urlQuery({ resource: query });
|
|
}
|
|
|
|
const m = query.match(/^([^@]+)@(.*)/);
|
|
if (m) {
|
|
const hostname = m[2];
|
|
return `https://${hostname}/.well-known/webfinger?` + urlQuery({ resource: `acct:${query}` });
|
|
}
|
|
|
|
throw new Error(`Invalid query (${query})`);
|
|
}
|