mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 22:09: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
|
|
@ -49,7 +49,6 @@ export default apiRoute((app) =>
|
|||
),
|
||||
async (context) => {
|
||||
const { acct } = context.req.valid("query");
|
||||
const { user } = context.get("auth");
|
||||
|
||||
// Check if acct is matching format username@domain.com or @username@domain.com
|
||||
const { username, domain } = parseUserAddress(acct);
|
||||
|
|
@ -93,9 +92,7 @@ export default apiRoute((app) =>
|
|||
}
|
||||
|
||||
// Fetch from remote instance
|
||||
const manager = await (user ?? User).getFederationRequester();
|
||||
|
||||
const uri = await User.webFinger(manager, username, domain);
|
||||
const uri = await User.webFinger(username, domain);
|
||||
|
||||
if (!uri) {
|
||||
throw ApiError.accountNotFound();
|
||||
|
|
|
|||
|
|
@ -91,9 +91,7 @@ export default apiRoute((app) =>
|
|||
const accounts: User[] = [];
|
||||
|
||||
if (resolve && domain) {
|
||||
const manager = await (user ?? User).getFederationRequester();
|
||||
|
||||
const uri = await User.webFinger(manager, username, domain);
|
||||
const uri = await User.webFinger(username, domain);
|
||||
|
||||
if (uri) {
|
||||
const resolvedUser = await User.resolve(uri);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { Account as AccountSchema, zBoolean } from "@versia/client/schemas";
|
|||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Emoji, Media, User } from "@versia/kit/db";
|
||||
import { Users } from "@versia/kit/tables";
|
||||
import * as VersiaEntities from "@versia/sdk/entities";
|
||||
import { and, eq, isNull } from "drizzle-orm";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
|
|
@ -186,12 +187,14 @@ export default apiRoute((app) =>
|
|||
|
||||
if (note && self.source) {
|
||||
self.source.note = note;
|
||||
self.note = await contentToHtml({
|
||||
"text/markdown": {
|
||||
content: note,
|
||||
remote: false,
|
||||
},
|
||||
});
|
||||
self.note = await contentToHtml(
|
||||
new VersiaEntities.TextContentFormat({
|
||||
"text/markdown": {
|
||||
content: note,
|
||||
remote: false,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (source?.privacy) {
|
||||
|
|
@ -275,23 +278,23 @@ export default apiRoute((app) =>
|
|||
for (const field of fields_attributes) {
|
||||
// Can be Markdown or plaintext, also has emojis
|
||||
const parsedName = await contentToHtml(
|
||||
{
|
||||
new VersiaEntities.TextContentFormat({
|
||||
"text/markdown": {
|
||||
content: field.name,
|
||||
remote: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
|
||||
const parsedValue = await contentToHtml(
|
||||
{
|
||||
new VersiaEntities.TextContentFormat({
|
||||
"text/markdown": {
|
||||
content: field.value,
|
||||
remote: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
undefined,
|
||||
true,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from "@versia/client/schemas";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Media } from "@versia/kit/db";
|
||||
import * as VersiaEntities from "@versia/sdk/entities";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
|
|
@ -228,12 +229,12 @@ export default apiRoute((app) => {
|
|||
const newNote = await note.updateFromData({
|
||||
author: user,
|
||||
content: statusText
|
||||
? {
|
||||
? new VersiaEntities.TextContentFormat({
|
||||
[content_type]: {
|
||||
content: statusText,
|
||||
remote: false,
|
||||
},
|
||||
}
|
||||
})
|
||||
: undefined,
|
||||
isSensitive: sensitive,
|
||||
spoilerText: spoiler_text,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from "@versia/client/schemas";
|
||||
import { RolePermission } from "@versia/client/schemas";
|
||||
import { Media, Note } from "@versia/kit/db";
|
||||
import * as VersiaEntities from "@versia/sdk/entities";
|
||||
import { describeRoute } from "hono-openapi";
|
||||
import { resolver, validator } from "hono-openapi/zod";
|
||||
import { z } from "zod";
|
||||
|
|
@ -176,12 +177,12 @@ export default apiRoute((app) =>
|
|||
|
||||
const newNote = await Note.fromData({
|
||||
author: user,
|
||||
content: {
|
||||
content: new VersiaEntities.TextContentFormat({
|
||||
[content_type]: {
|
||||
content: status ?? "",
|
||||
remote: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
visibility,
|
||||
isSensitive: sensitive ?? false,
|
||||
spoilerText: spoiler_text ?? "",
|
||||
|
|
|
|||
|
|
@ -198,15 +198,7 @@ export default apiRoute((app) =>
|
|||
}
|
||||
|
||||
if (resolve && domain) {
|
||||
const manager = await (
|
||||
user ?? User
|
||||
).getFederationRequester();
|
||||
|
||||
const uri = await User.webFinger(
|
||||
manager,
|
||||
username,
|
||||
domain,
|
||||
);
|
||||
const uri = await User.webFinger(username, domain);
|
||||
|
||||
if (uri) {
|
||||
const newUser = await User.resolve(uri);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue