mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49: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, handleZodError } from "@/api";
|
||||
import { Status as StatusSchema } from "@versia/client/schemas";
|
||||
import { Note as NoteSchema } from "@versia/federation/schemas";
|
||||
import { Note } from "@versia/kit/db";
|
||||
import { Notes } from "@versia/kit/tables";
|
||||
import { NoteSchema } from "@versia/sdk/schemas";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { apiRoute, handleZodError } from "@/api";
|
||||
import { Status as StatusSchema } from "@versia/client/schemas";
|
||||
import { URICollection as URICollectionSchema } from "@versia/federation/schemas";
|
||||
import type { URICollection } from "@versia/federation/types";
|
||||
import { Note, db } from "@versia/kit/db";
|
||||
import { Notes } from "@versia/kit/tables";
|
||||
import * as VersiaEntities from "@versia/sdk/entities";
|
||||
import { URICollectionSchema } from "@versia/sdk/schemas";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
@ -88,39 +88,39 @@ export default apiRoute((app) =>
|
|||
),
|
||||
);
|
||||
|
||||
const uriCollection = {
|
||||
author: note.author.getUri().href,
|
||||
const uriCollection = new VersiaEntities.URICollection({
|
||||
author: note.author.getUri(),
|
||||
first: new URL(
|
||||
`/notes/${note.id}/quotes?offset=0`,
|
||||
config.http.base_url,
|
||||
).href,
|
||||
),
|
||||
last:
|
||||
replyCount > limit
|
||||
? new URL(
|
||||
`/notes/${note.id}/quotes?offset=${replyCount - limit}`,
|
||||
config.http.base_url,
|
||||
).href
|
||||
)
|
||||
: new URL(
|
||||
`/notes/${note.id}/quotes`,
|
||||
config.http.base_url,
|
||||
).href,
|
||||
),
|
||||
next:
|
||||
offset + limit < replyCount
|
||||
? new URL(
|
||||
`/notes/${note.id}/quotes?offset=${offset + limit}`,
|
||||
config.http.base_url,
|
||||
).href
|
||||
)
|
||||
: null,
|
||||
previous:
|
||||
offset - limit >= 0
|
||||
? new URL(
|
||||
`/notes/${note.id}/quotes?offset=${offset - limit}`,
|
||||
config.http.base_url,
|
||||
).href
|
||||
)
|
||||
: null,
|
||||
total: replyCount,
|
||||
items: replies.map((reply) => reply.getUri().href),
|
||||
} satisfies URICollection;
|
||||
items: replies.map((reply) => reply.getUri()),
|
||||
});
|
||||
|
||||
// If base_url uses https and request uses http, rewrite request to use https
|
||||
// This fixes reverse proxy errors
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { apiRoute, handleZodError } from "@/api";
|
||||
import { Status as StatusSchema } from "@versia/client/schemas";
|
||||
import { URICollection as URICollectionSchema } from "@versia/federation/schemas";
|
||||
import type { URICollection } from "@versia/federation/types";
|
||||
import { Note, db } from "@versia/kit/db";
|
||||
import { Notes } from "@versia/kit/tables";
|
||||
import * as VersiaEntities from "@versia/sdk/entities";
|
||||
import { URICollectionSchema } from "@versia/sdk/schemas";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
@ -86,39 +86,39 @@ export default apiRoute((app) =>
|
|||
),
|
||||
);
|
||||
|
||||
const uriCollection = {
|
||||
author: note.author.getUri().href,
|
||||
const uriCollection = new VersiaEntities.URICollection({
|
||||
author: note.author.getUri(),
|
||||
first: new URL(
|
||||
`/notes/${note.id}/replies?offset=0`,
|
||||
config.http.base_url,
|
||||
).href,
|
||||
),
|
||||
last:
|
||||
replyCount > limit
|
||||
? new URL(
|
||||
`/notes/${note.id}/replies?offset=${replyCount - limit}`,
|
||||
config.http.base_url,
|
||||
).href
|
||||
)
|
||||
: new URL(
|
||||
`/notes/${note.id}/replies`,
|
||||
config.http.base_url,
|
||||
).href,
|
||||
),
|
||||
next:
|
||||
offset + limit < replyCount
|
||||
? new URL(
|
||||
`/notes/${note.id}/replies?offset=${offset + limit}`,
|
||||
config.http.base_url,
|
||||
).href
|
||||
)
|
||||
: null,
|
||||
previous:
|
||||
offset - limit >= 0
|
||||
? new URL(
|
||||
`/notes/${note.id}/replies?offset=${offset - limit}`,
|
||||
config.http.base_url,
|
||||
).href
|
||||
)
|
||||
: null,
|
||||
total: replyCount,
|
||||
items: replies.map((reply) => reply.getUri().href),
|
||||
} satisfies URICollection;
|
||||
items: replies.map((reply) => reply.getUri()),
|
||||
});
|
||||
|
||||
// If base_url uses https and request uses http, rewrite request to use https
|
||||
// This fixes reverse proxy errors
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue