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'
|
2022-04-17 12:03:53 +00:00
|
|
|
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') {
|
2022-04-17 12:03:53 +00:00
|
|
|
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
|
|
|
}
|