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

27 wiersze
889 B
TypeScript
Czysty Zwykły widok Historia

2021-12-23 14:14:06 +00:00
import { assertSuccessJsonResponse } from '../assertSuccessJsonResponse'
import { z } from 'zod'
2022-01-03 12:26:17 +00:00
import { getDefaultTimeoutMilliseconds } from '../getDefaultTimeoutMilliseconds'
2022-11-22 15:37:11 +00:00
import RobotsTxt from '../RobotsTxt/RobotsTxt.js'
2021-12-23 14:14:06 +00:00
const wellKnownSchema = z.object({
links: z.array(
z.object({
rel: z.string(),
href: z.string()
})
)
})
export type WellKnown = z.infer<typeof wellKnownSchema>
2022-11-22 15:37:11 +00:00
export const retrieveWellKnown = async (domain: string, robotsTxt: RobotsTxt): Promise<WellKnown> => {
2022-09-18 11:32:25 +00:00
console.info('Retrieving well known', { domain })
2021-12-23 14:14:06 +00:00
const wellKnownUrl = `https://${domain}/.well-known/nodeinfo`
2022-11-22 15:37:11 +00:00
const wellKnownResponse = await robotsTxt.getIfAllowed(wellKnownUrl, {
timeout: getDefaultTimeoutMilliseconds(),
maxContentLength: 5000
})
2021-12-23 14:14:06 +00:00
assertSuccessJsonResponse(wellKnownResponse)
return wellKnownSchema.parse(wellKnownResponse.data)
}