mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(federation): ⬆️ Use @lysand-org/federation v2.0.0
This commit is contained in:
parent
47ce60494a
commit
70cd00cfa8
17 changed files with 56 additions and 60 deletions
|
|
@ -1,8 +1,6 @@
|
|||
import { debugRequest } from "@/api";
|
||||
import {
|
||||
type EntityValidator,
|
||||
SignatureConstructor,
|
||||
} from "@lysand-org/federation";
|
||||
import { SignatureConstructor } from "@lysand-org/federation";
|
||||
import type { Entity, Undo } from "@lysand-org/federation/types";
|
||||
import { config } from "config-manager";
|
||||
import type { User } from "~/packages/database-interface/user";
|
||||
import { LogLevel, LogManager } from "~/packages/log-manager";
|
||||
|
|
@ -11,7 +9,7 @@ export const localObjectUri = (id: string) =>
|
|||
new URL(`/objects/${id}`, config.http.base_url).toString();
|
||||
|
||||
export const objectToInboxRequest = async (
|
||||
object: typeof EntityValidator.$Entity,
|
||||
object: Entity,
|
||||
author: User,
|
||||
userToSendTo: User,
|
||||
): Promise<Request> => {
|
||||
|
|
@ -68,10 +66,7 @@ export const objectToInboxRequest = async (
|
|||
return signed;
|
||||
};
|
||||
|
||||
export const undoFederationRequest = (
|
||||
undoer: User,
|
||||
uri: string,
|
||||
): typeof EntityValidator.$Undo => {
|
||||
export const undoFederationRequest = (undoer: User, uri: string): Undo => {
|
||||
const id = crypto.randomUUID();
|
||||
return {
|
||||
type: "Undo",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { EntityValidator } from "@lysand-org/federation";
|
||||
import type { ServerMetadata } from "@lysand-org/federation/types";
|
||||
import { db } from "~/drizzle/db";
|
||||
import { Instances } from "~/drizzle/schema";
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ export const addInstanceIfNotExists = async (url: string) => {
|
|||
// Fetch the instance configuration
|
||||
const metadata = (await fetch(new URL("/.well-known/lysand", origin)).then(
|
||||
(res) => res.json(),
|
||||
)) as typeof EntityValidator.$ServerMetadata;
|
||||
)) as ServerMetadata;
|
||||
|
||||
if (metadata.type !== "ServerMetadata") {
|
||||
throw new Error("Invalid instance metadata (wrong type)");
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { EntityValidator } from "@lysand-org/federation";
|
||||
import type { Like } from "@lysand-org/federation/types";
|
||||
import { config } from "config-manager";
|
||||
import { type InferSelectModel, and, eq } from "drizzle-orm";
|
||||
import { db } from "~/drizzle/db";
|
||||
|
|
@ -6,12 +6,12 @@ import { Likes, Notifications } from "~/drizzle/schema";
|
|||
import type { Note } from "~/packages/database-interface/note";
|
||||
import type { User } from "~/packages/database-interface/user";
|
||||
|
||||
export type Like = InferSelectModel<typeof Likes>;
|
||||
export type LikeType = InferSelectModel<typeof Likes>;
|
||||
|
||||
/**
|
||||
* Represents a Like entity in the database.
|
||||
*/
|
||||
export const likeToLysand = (like: Like): typeof EntityValidator.$Like => {
|
||||
export const likeToLysand = (like: LikeType): Like => {
|
||||
return {
|
||||
id: like.id,
|
||||
// biome-ignore lint/suspicious/noExplicitAny: to be rewritten
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { mentionValidator } from "@/api";
|
|||
import { dualLogger } from "@/loggers";
|
||||
import { sanitizeHtml, sanitizeHtmlInline } from "@/sanitization";
|
||||
import markdownItTaskLists from "@hackmd/markdown-it-task-lists";
|
||||
import type { EntityValidator } from "@lysand-org/federation";
|
||||
import type { ContentFormat } from "@lysand-org/federation/types";
|
||||
import { config } from "config-manager";
|
||||
import {
|
||||
type InferSelectModel,
|
||||
|
|
@ -373,7 +373,7 @@ export const replaceTextMentions = (text: string, mentions: User[]) => {
|
|||
};
|
||||
|
||||
export const contentToHtml = async (
|
||||
content: typeof EntityValidator.$ContentFormat,
|
||||
content: ContentFormat,
|
||||
mentions: User[] = [],
|
||||
inline = false,
|
||||
): Promise<string> => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
import { dualLogger } from "@/loggers";
|
||||
import type { EntityValidator } from "@lysand-org/federation";
|
||||
import type {
|
||||
Follow,
|
||||
FollowAccept,
|
||||
FollowReject,
|
||||
} from "@lysand-org/federation/types";
|
||||
import { config } from "config-manager";
|
||||
import { type InferSelectModel, and, eq, sql } from "drizzle-orm";
|
||||
import { db } from "~/drizzle/db";
|
||||
|
|
@ -505,7 +509,7 @@ export const getRelationshipToOtherUser = async (
|
|||
export const followRequestToLysand = (
|
||||
follower: User,
|
||||
followee: User,
|
||||
): typeof EntityValidator.$Follow => {
|
||||
): Follow => {
|
||||
if (follower.isRemote()) {
|
||||
throw new Error("Follower must be a local user");
|
||||
}
|
||||
|
|
@ -533,7 +537,7 @@ export const followRequestToLysand = (
|
|||
export const followAcceptToLysand = (
|
||||
follower: User,
|
||||
followee: User,
|
||||
): typeof EntityValidator.$FollowAccept => {
|
||||
): FollowAccept => {
|
||||
if (!follower.isRemote()) {
|
||||
throw new Error("Follower must be a remote user");
|
||||
}
|
||||
|
|
@ -561,7 +565,7 @@ export const followAcceptToLysand = (
|
|||
export const followRejectToLysand = (
|
||||
follower: User,
|
||||
followee: User,
|
||||
): typeof EntityValidator.$FollowReject => {
|
||||
): FollowReject => {
|
||||
return {
|
||||
...followAcceptToLysand(follower, followee),
|
||||
type: "FollowReject",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue