mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
refactor(federation): ♻️ Refactor code to use less fetch calls and instead use FederationRequester
This commit is contained in:
parent
833f261392
commit
daba8e8178
|
|
@ -104,7 +104,7 @@
|
||||||
"@json2csv/plainjs": "^7.0.6",
|
"@json2csv/plainjs": "^7.0.6",
|
||||||
"@logtape/logtape": "npm:@jsr/logtape__logtape@0.4.2",
|
"@logtape/logtape": "npm:@jsr/logtape__logtape@0.4.2",
|
||||||
"@lysand-org/client": "^0.2.5",
|
"@lysand-org/client": "^0.2.5",
|
||||||
"@lysand-org/federation": "2.1.8",
|
"@lysand-org/federation": "^2.1.9-test2",
|
||||||
"@oclif/core": "^4.0.14",
|
"@oclif/core": "^4.0.14",
|
||||||
"@sentry/bun": "^8.19.0",
|
"@sentry/bun": "^8.19.0",
|
||||||
"@tufjs/canonical-json": "^2.0.0",
|
"@tufjs/canonical-json": "^2.0.0",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
import { getLogger } from "@logtape/logtape";
|
import { getLogger } from "@logtape/logtape";
|
||||||
import { EntityValidator, type ValidationError } from "@lysand-org/federation";
|
import {
|
||||||
|
EntityValidator,
|
||||||
|
FederationRequester,
|
||||||
|
type ValidationError,
|
||||||
|
} from "@lysand-org/federation";
|
||||||
import type { ServerMetadata } from "@lysand-org/federation/types";
|
import type { ServerMetadata } from "@lysand-org/federation/types";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { config } from "config-manager";
|
import { config } from "config-manager";
|
||||||
|
|
@ -135,9 +139,13 @@ export class Instance extends BaseInterface<typeof Instances> {
|
||||||
const logger = getLogger("federation");
|
const logger = getLogger("federation");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(wellKnownUrl, {
|
const { raw: response } = await FederationRequester.get(
|
||||||
proxy: config.http.proxy.address,
|
wellKnownUrl,
|
||||||
});
|
{
|
||||||
|
// @ts-expect-error Bun extension
|
||||||
|
proxy: config.http.proxy.address,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!(
|
!(
|
||||||
|
|
@ -190,9 +198,13 @@ export class Instance extends BaseInterface<typeof Instances> {
|
||||||
const logger = getLogger("federation");
|
const logger = getLogger("federation");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(wellKnownUrl, {
|
const { raw: response } = await FederationRequester.get(
|
||||||
proxy: config.http.proxy.address,
|
wellKnownUrl,
|
||||||
});
|
{
|
||||||
|
// @ts-expect-error Bun extension
|
||||||
|
proxy: config.http.proxy.address,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
logger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
logger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
||||||
|
|
@ -223,9 +235,13 @@ export class Instance extends BaseInterface<typeof Instances> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const metadataResponse = await fetch(metadataUrl.href, {
|
const { raw: metadataResponse } = await FederationRequester.get(
|
||||||
proxy: config.http.proxy.address,
|
metadataUrl.href,
|
||||||
});
|
{
|
||||||
|
// @ts-expect-error Bun extension
|
||||||
|
proxy: config.http.proxy.address,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (!metadataResponse.ok) {
|
if (!metadataResponse.ok) {
|
||||||
logger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
logger.error`Failed to fetch ActivityPub metadata for instance ${chalk.bold(
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import type {
|
||||||
Attachment as ApiAttachment,
|
Attachment as ApiAttachment,
|
||||||
Status as ApiStatus,
|
Status as ApiStatus,
|
||||||
} from "@lysand-org/client/types";
|
} from "@lysand-org/client/types";
|
||||||
import { EntityValidator } from "@lysand-org/federation";
|
import { EntityValidator, FederationRequester } from "@lysand-org/federation";
|
||||||
import type {
|
import type {
|
||||||
ContentFormat,
|
ContentFormat,
|
||||||
Note as LysandNote,
|
Note as LysandNote,
|
||||||
|
|
@ -591,11 +591,8 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
||||||
throw new Error(`Invalid URI to parse ${uri}`);
|
throw new Error(`Invalid URI to parse ${uri}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(uri, {
|
const { raw: response } = await FederationRequester.get(uri, {
|
||||||
method: "GET",
|
// @ts-expect-error Bun extension
|
||||||
headers: {
|
|
||||||
Accept: "application/json",
|
|
||||||
},
|
|
||||||
proxy: config.http.proxy.address,
|
proxy: config.http.proxy.address,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,7 @@ import type {
|
||||||
Account as ApiAccount,
|
Account as ApiAccount,
|
||||||
Mention as ApiMention,
|
Mention as ApiMention,
|
||||||
} from "@lysand-org/client/types";
|
} from "@lysand-org/client/types";
|
||||||
import {
|
import { EntityValidator, FederationRequester } from "@lysand-org/federation";
|
||||||
EntityValidator,
|
|
||||||
type FederationRequester,
|
|
||||||
} from "@lysand-org/federation";
|
|
||||||
import type { Entity, User as LysandUser } from "@lysand-org/federation/types";
|
import type { Entity, User as LysandUser } from "@lysand-org/federation/types";
|
||||||
import {
|
import {
|
||||||
type InferInsertModel,
|
type InferInsertModel,
|
||||||
|
|
@ -343,9 +340,8 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
||||||
uri: string,
|
uri: string,
|
||||||
instance: Instance,
|
instance: Instance,
|
||||||
): Promise<User> {
|
): Promise<User> {
|
||||||
const response = await fetch(uri, {
|
const { raw: response } = await FederationRequester.get(uri, {
|
||||||
method: "GET",
|
// @ts-expect-error Bun extension
|
||||||
headers: { Accept: "application/json" },
|
|
||||||
proxy: config.http.proxy.address,
|
proxy: config.http.proxy.address,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue