mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
refactor(federation): ♻️ Rewrite federation SDK
This commit is contained in:
parent
ad1dc13a51
commit
d638610361
72 changed files with 2137 additions and 738 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import { apiRoute } from "@/api";
|
||||
import { urlToContentFormat } from "@/content_types";
|
||||
import { InstanceMetadata as InstanceMetadataSchema } from "@versia/federation/schemas";
|
||||
import { User } from "@versia/kit/db";
|
||||
import { Users } from "@versia/kit/tables";
|
||||
import { InstanceMetadataSchema } from "@versia/sdk/schemas";
|
||||
import { asc } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver } from "hono-openapi/zod";
|
||||
|
|
|
|||
|
|
@ -6,10 +6,9 @@ import {
|
|||
webfingerMention,
|
||||
} from "@/api";
|
||||
import { getLogger } from "@logtape/logtape";
|
||||
import type { ResponseError } from "@versia/federation";
|
||||
import { WebFinger } from "@versia/federation/schemas";
|
||||
import { User } from "@versia/kit/db";
|
||||
import { Users } from "@versia/kit/tables";
|
||||
import { WebFingerSchema } from "@versia/sdk/schemas";
|
||||
import { and, eq, isNull } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
@ -28,7 +27,7 @@ export default apiRoute((app) =>
|
|||
description: "User information",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: resolver(WebFinger),
|
||||
schema: resolver(WebFingerSchema),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -81,23 +80,22 @@ export default apiRoute((app) =>
|
|||
throw ApiError.accountNotFound();
|
||||
}
|
||||
|
||||
let activityPubUrl = "";
|
||||
let activityPubUrl: URL | null = null;
|
||||
|
||||
if (config.federation.bridge) {
|
||||
const manager = await User.getFederationRequester();
|
||||
|
||||
try {
|
||||
activityPubUrl = await manager.webFinger(
|
||||
user.data.username,
|
||||
config.http.base_url.host,
|
||||
"application/activity+json",
|
||||
config.federation.bridge.url.origin,
|
||||
);
|
||||
activityPubUrl =
|
||||
await User.federationRequester.resolveWebFinger(
|
||||
user.data.username,
|
||||
config.http.base_url.host,
|
||||
"application/activity+json",
|
||||
config.federation.bridge.url.origin,
|
||||
);
|
||||
} catch (e) {
|
||||
const error = e as ResponseError;
|
||||
const error = e as ApiError;
|
||||
|
||||
getLogger(["federation", "bridge"])
|
||||
.error`Error from bridge: ${await error.response.data}`;
|
||||
.error`Error from bridge: ${error.message}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +110,7 @@ export default apiRoute((app) =>
|
|||
? {
|
||||
rel: "self",
|
||||
type: "application/activity+json",
|
||||
href: activityPubUrl,
|
||||
href: activityPubUrl.href,
|
||||
}
|
||||
: undefined,
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue