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,10 +1,10 @@
|
|||
import { apiRoute, handleZodError } from "@/api";
|
||||
import type { Entity } from "@versia/federation/types";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
import { ApiError } from "~/classes/errors/api-error";
|
||||
import { InboxJobType, inboxQueue } from "~/classes/queues/inbox";
|
||||
import type { JSONObject } from "~/packages/federation/types";
|
||||
|
||||
export default apiRoute((app) =>
|
||||
app.post(
|
||||
|
|
@ -89,7 +89,7 @@ export default apiRoute((app) =>
|
|||
),
|
||||
validator("json", z.any(), handleZodError),
|
||||
async (context) => {
|
||||
const body: Entity = await context.req.valid("json");
|
||||
const body: JSONObject = await context.req.valid("json");
|
||||
|
||||
await inboxQueue.add(InboxJobType.ProcessEntity, {
|
||||
data: body,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { apiRoute, handleZodError } from "@/api";
|
||||
import { User as UserSchema } from "@versia/federation/schemas";
|
||||
import { User } from "@versia/kit/db";
|
||||
import { UserSchema } from "@versia/sdk/schemas";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
|
|
@ -43,6 +43,7 @@ export default apiRoute((app) =>
|
|||
}),
|
||||
handleZodError,
|
||||
),
|
||||
// @ts-expect-error
|
||||
async (context) => {
|
||||
const { uuid } = context.req.valid("param");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
import { apiRoute, handleZodError } from "@/api";
|
||||
import {
|
||||
Collection as CollectionSchema,
|
||||
Note as NoteSchema,
|
||||
} from "@versia/federation/schemas";
|
||||
import { Note, User, db } from "@versia/kit/db";
|
||||
import { Notes } from "@versia/kit/tables";
|
||||
import * as VersiaEntities from "@versia/sdk/entities";
|
||||
import { CollectionSchema, NoteSchema } from "@versia/sdk/schemas";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
@ -96,35 +94,35 @@ export default apiRoute((app) =>
|
|||
),
|
||||
);
|
||||
|
||||
const json = {
|
||||
const json = new VersiaEntities.Collection({
|
||||
first: new URL(
|
||||
`/users/${uuid}/outbox?page=1`,
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
),
|
||||
last: new URL(
|
||||
`/users/${uuid}/outbox?page=${Math.ceil(
|
||||
totalNotes / NOTES_PER_PAGE,
|
||||
)}`,
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
),
|
||||
total: totalNotes,
|
||||
author: author.getUri().toString(),
|
||||
author: author.getUri(),
|
||||
next:
|
||||
notes.length === NOTES_PER_PAGE
|
||||
? new URL(
|
||||
`/users/${uuid}/outbox?page=${pageNumber + 1}`,
|
||||
config.http.base_url,
|
||||
).toString()
|
||||
)
|
||||
: null,
|
||||
previous:
|
||||
pageNumber > 1
|
||||
? new URL(
|
||||
`/users/${uuid}/outbox?page=${pageNumber - 1}`,
|
||||
config.http.base_url,
|
||||
).toString()
|
||||
)
|
||||
: null,
|
||||
items: notes.map((note) => note.toVersia()),
|
||||
};
|
||||
});
|
||||
|
||||
const { headers } = await author.sign(
|
||||
json,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue