mirror of
https://github.com/byulmaru/quesdon
synced 2024-11-27 06:18:02 +09:00
Instance Detector 추가
This commit is contained in:
parent
f2f566edd7
commit
cdd6f1661a
36
src/server/utils/detectInstance.ts
Normal file
36
src/server/utils/detectInstance.ts
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user