1
0
mirror of https://github.com/byulmaru/quesdon synced 2024-11-27 06:18:02 +09:00

Instance Detector 추가

This commit is contained in:
DW 2019-11-11 01:32:07 +11:00
parent f2f566edd7
commit cdd6f1661a

View File

@ -0,0 +1,36 @@
import fetch from 'node-fetch';
type nodeinfoMeta =
{
links: nodeinfoVersionList[];
};
type nodeinfoVersionList =
{
rel: string;
href: string;
}
type nodeinfo =
{
version: string;
software: { name: string; version: string };
// irrelevent properties skipped
}
export default async function detectInstance(url: string): Promise<string|undefined>
{
const parsedURL = new URL(url);
if(parsedURL.hostname === 'twitter.com')
return 'twitter';
// fediverse
const nodeinfoMeta: nodeinfoMeta = await fetch(`${parsedURL.origin}/.well-known/nodeinfo`).then(r => r.json());
const nodeinfoLink = nodeinfoMeta.links.find(elem => elem.rel === 'http://nodeinfo.diaspora.software/ns/schema/2.0');
// TODO: add support for 1.0 as a fallback? All latest versions of major AP softwares seem to support 2.0 tho
if(!nodeinfoLink)
return undefined;
const nodeinfo: nodeinfo = await fetch(`${nodeinfoLink.href}`).then(r => r.json());
return nodeinfo.software.name;
}