fedicrawl/application/src/Fediverse/NodeInfo/retrieveDomainNodeInfo.ts

19 wiersze
676 B
TypeScript
Czysty Zwykły widok Historia

2022-11-22 15:37:11 +00:00
import RobotsTxt from '../RobotsTxt/RobotsTxt.js'
2021-12-23 14:14:06 +00:00
import { retrieveWellKnown } from './retrieveWellKnown'
import { retrieveNodeInfo, NodeInfo } from './retrieveNodeInfo'
import { NoSupportedLinkError } from './NoSupportedLinkError'
2021-12-23 14:14:06 +00:00
2022-09-18 11:32:25 +00:00
export const retrieveDomainNodeInfo = async (
2022-11-22 15:37:11 +00:00
domain: string,
robotsTxt: RobotsTxt
2022-09-18 11:32:25 +00:00
): Promise<NodeInfo> => {
2022-11-22 15:37:11 +00:00
const wellKnown = await retrieveWellKnown(domain, robotsTxt)
2022-09-18 11:32:25 +00:00
const link = wellKnown.links.find(
(link) => link.rel === 'http://nodeinfo.diaspora.software/ns/schema/2.0'
)
2021-12-23 14:14:06 +00:00
if (typeof link === 'undefined') {
throw new NoSupportedLinkError(domain)
2021-12-23 14:14:06 +00:00
}
2022-11-29 13:11:27 +00:00
return await retrieveNodeInfo(new URL(link.href), robotsTxt)
2021-12-23 14:14:06 +00:00
}