mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(federation): ⬆️ Refactor code to use v2.2 of federation SDK
This commit is contained in:
parent
aca837cb16
commit
ad9ed2598c
12 changed files with 73 additions and 79 deletions
|
|
@ -140,15 +140,14 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
const logger = getLogger("federation");
|
||||
|
||||
try {
|
||||
const { ok, raw, data } = await FederationRequester.get(
|
||||
wellKnownUrl,
|
||||
{
|
||||
const { ok, raw, data } = await new FederationRequester()
|
||||
.get(wellKnownUrl, {
|
||||
// @ts-expect-error Bun extension
|
||||
proxy: config.http.proxy.address,
|
||||
},
|
||||
).catch((e) => ({
|
||||
...(e as ResponseError).response,
|
||||
}));
|
||||
})
|
||||
.catch((e) => ({
|
||||
...(e as ResponseError).response,
|
||||
}));
|
||||
|
||||
if (!(ok && raw.headers.get("content-type")?.includes("json"))) {
|
||||
// If the server doesn't have a Lysand well-known endpoint, it's not a Lysand instance
|
||||
|
|
@ -200,18 +199,20 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
raw: response,
|
||||
ok,
|
||||
data: wellKnown,
|
||||
} = await FederationRequester.get<{
|
||||
links: { rel: string; href: string }[];
|
||||
}>(wellKnownUrl, {
|
||||
// @ts-expect-error Bun extension
|
||||
proxy: config.http.proxy.address,
|
||||
}).catch((e) => ({
|
||||
...(
|
||||
e as ResponseError<{
|
||||
links: { rel: string; href: string }[];
|
||||
}>
|
||||
).response,
|
||||
}));
|
||||
} = await new FederationRequester()
|
||||
.get<{
|
||||
links: { rel: string; href: string }[];
|
||||
}>(wellKnownUrl, {
|
||||
// @ts-expect-error Bun extension
|
||||
proxy: config.http.proxy.address,
|
||||
})
|
||||
.catch((e) => ({
|
||||
...(
|
||||
e as ResponseError<{
|
||||
links: { rel: string; href: string }[];
|
||||
}>
|
||||
).response,
|
||||
}));
|
||||
|
||||
if (!ok) {
|
||||
logger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
||||
|
|
@ -244,30 +245,32 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
raw: metadataResponse,
|
||||
ok: ok2,
|
||||
data: metadata,
|
||||
} = await FederationRequester.get<{
|
||||
metadata: {
|
||||
nodeName?: string;
|
||||
title?: string;
|
||||
nodeDescription?: string;
|
||||
description?: string;
|
||||
};
|
||||
software: { version: string };
|
||||
}>(metadataUrl.href, {
|
||||
// @ts-expect-error Bun extension
|
||||
proxy: config.http.proxy.address,
|
||||
}).catch((e) => ({
|
||||
...(
|
||||
e as ResponseError<{
|
||||
metadata: {
|
||||
nodeName?: string;
|
||||
title?: string;
|
||||
nodeDescription?: string;
|
||||
description?: string;
|
||||
};
|
||||
software: { version: string };
|
||||
}>
|
||||
).response,
|
||||
}));
|
||||
} = await new FederationRequester()
|
||||
.get<{
|
||||
metadata: {
|
||||
nodeName?: string;
|
||||
title?: string;
|
||||
nodeDescription?: string;
|
||||
description?: string;
|
||||
};
|
||||
software: { version: string };
|
||||
}>(metadataUrl.href, {
|
||||
// @ts-expect-error Bun extension
|
||||
proxy: config.http.proxy.address,
|
||||
})
|
||||
.catch((e) => ({
|
||||
...(
|
||||
e as ResponseError<{
|
||||
metadata: {
|
||||
nodeName?: string;
|
||||
title?: string;
|
||||
nodeDescription?: string;
|
||||
description?: string;
|
||||
};
|
||||
software: { version: string };
|
||||
}>
|
||||
).response,
|
||||
}));
|
||||
|
||||
if (!ok2) {
|
||||
logger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
||||
|
|
|
|||
|
|
@ -592,7 +592,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
|||
throw new Error(`Invalid URI to parse ${uri}`);
|
||||
}
|
||||
|
||||
const { data } = await FederationRequester.get(uri, {
|
||||
const { data } = await new FederationRequester().get(uri, {
|
||||
// @ts-expect-error Bun extension
|
||||
proxy: config.http.proxy.address,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -201,12 +201,13 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
static async webFinger(
|
||||
manager: FederationRequester,
|
||||
username: string,
|
||||
hostname: string,
|
||||
): Promise<string> {
|
||||
return (
|
||||
(await manager.webFinger(username).catch(() => null)) ??
|
||||
(await manager.webFinger(username, hostname).catch(() => null)) ??
|
||||
(await manager.webFinger(
|
||||
username,
|
||||
manager.url.hostname,
|
||||
hostname,
|
||||
"application/activity+json",
|
||||
))
|
||||
);
|
||||
|
|
@ -340,7 +341,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
uri: string,
|
||||
instance: Instance,
|
||||
): Promise<User> {
|
||||
const { data: json } = await FederationRequester.get<
|
||||
const { data: json } = await new FederationRequester().get<
|
||||
Partial<LysandUser>
|
||||
>(uri, {
|
||||
// @ts-expect-error Bun extension
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue