mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
refactor(federation): ⬆️ Refactor code to use v2.2 of federation SDK
This commit is contained in:
parent
aca837cb16
commit
ad9ed2598c
|
|
@ -320,12 +320,13 @@ export const parseTextMentions = async (
|
|||
author.data.privateKey ?? "",
|
||||
author.getUri(),
|
||||
);
|
||||
const manager = new FederationRequester(
|
||||
new URL(`https://${person?.[2] ?? ""}`),
|
||||
signatureConstructor,
|
||||
);
|
||||
const manager = new FederationRequester(signatureConstructor);
|
||||
|
||||
const uri = await User.webFinger(manager, person?.[1] ?? "");
|
||||
const uri = await User.webFinger(
|
||||
manager,
|
||||
person?.[1] ?? "",
|
||||
person?.[2] ?? "",
|
||||
);
|
||||
|
||||
const user = await User.resolve(uri);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,12 +51,9 @@ export default class FederationUserFetch extends BaseCommand<
|
|||
requester.data.privateKey ?? "",
|
||||
requester.getUri(),
|
||||
);
|
||||
const manager = new FederationRequester(
|
||||
new URL(`https://${host}`),
|
||||
signatureConstructor,
|
||||
);
|
||||
const manager = new FederationRequester(signatureConstructor);
|
||||
|
||||
const uri = await User.webFinger(manager, username);
|
||||
const uri = await User.webFinger(manager, username, host);
|
||||
|
||||
const newUser = await User.resolve(uri);
|
||||
|
||||
|
|
|
|||
|
|
@ -51,12 +51,9 @@ export default class FederationUserFinger extends BaseCommand<
|
|||
requester.data.privateKey ?? "",
|
||||
requester.getUri(),
|
||||
);
|
||||
const manager = new FederationRequester(
|
||||
new URL(`https://${host}`),
|
||||
signatureConstructor,
|
||||
);
|
||||
const manager = new FederationRequester(signatureConstructor);
|
||||
|
||||
const uri = await User.webFinger(manager, username);
|
||||
const uri = await User.webFinger(manager, username, host);
|
||||
|
||||
spinner.succeed("Fetched user URI");
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@
|
|||
"@json2csv/plainjs": "^7.0.6",
|
||||
"@logtape/logtape": "npm:@jsr/logtape__logtape@0.4.2",
|
||||
"@lysand-org/client": "^0.2.5",
|
||||
"@lysand-org/federation": "^2.1.10",
|
||||
"@lysand-org/federation": "^2.2.0-rc.2",
|
||||
"@oclif/core": "^4.0.14",
|
||||
"@sentry/bun": "^8.20.0",
|
||||
"@tufjs/canonical-json": "^2.0.0",
|
||||
|
|
|
|||
|
|
@ -140,13 +140,12 @@ 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) => ({
|
||||
})
|
||||
.catch((e) => ({
|
||||
...(e as ResponseError).response,
|
||||
}));
|
||||
|
||||
|
|
@ -200,12 +199,14 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
raw: response,
|
||||
ok,
|
||||
data: wellKnown,
|
||||
} = await FederationRequester.get<{
|
||||
} = await new FederationRequester()
|
||||
.get<{
|
||||
links: { rel: string; href: string }[];
|
||||
}>(wellKnownUrl, {
|
||||
// @ts-expect-error Bun extension
|
||||
proxy: config.http.proxy.address,
|
||||
}).catch((e) => ({
|
||||
})
|
||||
.catch((e) => ({
|
||||
...(
|
||||
e as ResponseError<{
|
||||
links: { rel: string; href: string }[];
|
||||
|
|
@ -244,7 +245,8 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
raw: metadataResponse,
|
||||
ok: ok2,
|
||||
data: metadata,
|
||||
} = await FederationRequester.get<{
|
||||
} = await new FederationRequester()
|
||||
.get<{
|
||||
metadata: {
|
||||
nodeName?: string;
|
||||
title?: string;
|
||||
|
|
@ -255,7 +257,8 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
}>(metadataUrl.href, {
|
||||
// @ts-expect-error Bun extension
|
||||
proxy: config.http.proxy.address,
|
||||
}).catch((e) => ({
|
||||
})
|
||||
.catch((e) => ({
|
||||
...(
|
||||
e as ResponseError<{
|
||||
metadata: {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -89,12 +89,9 @@ export default (app: Hono) =>
|
|||
requester.data.privateKey ?? "",
|
||||
requester.getUri(),
|
||||
);
|
||||
const manager = new FederationRequester(
|
||||
new URL(`https://${domain}`),
|
||||
signatureConstructor,
|
||||
);
|
||||
const manager = new FederationRequester(signatureConstructor);
|
||||
|
||||
const uri = await User.webFinger(manager, username);
|
||||
const uri = await User.webFinger(manager, username, domain);
|
||||
|
||||
const foundAccount = await User.resolve(uri);
|
||||
|
||||
|
|
|
|||
|
|
@ -100,12 +100,9 @@ export default (app: Hono) =>
|
|||
requester.data.privateKey ?? "",
|
||||
requester.getUri(),
|
||||
);
|
||||
const manager = new FederationRequester(
|
||||
new URL(`https://${host}`),
|
||||
signatureConstructor,
|
||||
);
|
||||
const manager = new FederationRequester(signatureConstructor);
|
||||
|
||||
const uri = await User.webFinger(manager, username);
|
||||
const uri = await User.webFinger(manager, username, host);
|
||||
|
||||
const resolvedUser = await User.resolve(uri);
|
||||
|
||||
|
|
|
|||
|
|
@ -139,11 +139,14 @@ export default (app: Hono) =>
|
|||
requester.getUri(),
|
||||
);
|
||||
const manager = new FederationRequester(
|
||||
new URL(`https://${domain}`),
|
||||
signatureConstructor,
|
||||
);
|
||||
|
||||
const uri = await User.webFinger(manager, username);
|
||||
const uri = await User.webFinger(
|
||||
manager,
|
||||
username,
|
||||
domain,
|
||||
);
|
||||
|
||||
const newUser = await User.resolve(uri);
|
||||
|
||||
|
|
|
|||
|
|
@ -90,16 +90,14 @@ export default (app: Hono) =>
|
|||
requester.getUri(),
|
||||
);
|
||||
|
||||
const manager = new FederationRequester(
|
||||
new URL(config.federation.bridge.url ?? ""),
|
||||
signatureConstructor,
|
||||
);
|
||||
const manager = new FederationRequester(signatureConstructor);
|
||||
|
||||
try {
|
||||
activityPubUrl = await manager.webFinger(
|
||||
user.data.username,
|
||||
new URL(config.http.base_url).host,
|
||||
"application/activity+json",
|
||||
config.federation.bridge.url,
|
||||
);
|
||||
} catch (e) {
|
||||
const error = e as ResponseError;
|
||||
|
|
|
|||
Loading…
Reference in a new issue