mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Finish full rewrite of server and testing systems
This commit is contained in:
parent
0e4d6b401c
commit
0541776d3d
32 changed files with 1168 additions and 916 deletions
|
|
@ -95,25 +95,3 @@ export const emojiToActivityPub = (emoji: Emoji): any => {
|
|||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const addAPEmojiIfNotExists = async (apEmoji: any) => {
|
||||
// replace any with your ActivityPub Emoji type
|
||||
const existingEmoji = await client.emoji.findFirst({
|
||||
where: {
|
||||
shortcode: apEmoji.name.replace(/:/g, ""),
|
||||
instance: null,
|
||||
},
|
||||
});
|
||||
|
||||
if (existingEmoji) return existingEmoji;
|
||||
|
||||
return await client.emoji.create({
|
||||
data: {
|
||||
shortcode: apEmoji.name.replace(/:/g, ""),
|
||||
url: apEmoji.icon.url,
|
||||
alt: apEmoji.icon.alt || null,
|
||||
content_type: apEmoji.icon.mediaType,
|
||||
visible_in_picker: true,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
import type { Like as LysandLike } from "~types/lysand/Object";
|
||||
import { getConfig } from "~classes/configmanager";
|
||||
import type { Like } from "@prisma/client";
|
||||
import { client } from "~database/datasource";
|
||||
import type { UserWithRelations } from "./User";
|
||||
import type { StatusWithRelations } from "./Status";
|
||||
import { ConfigManager } from "config-manager";
|
||||
|
||||
const config = await new ConfigManager({}).getConfig();
|
||||
|
||||
/**
|
||||
* Represents a Like entity in the database.
|
||||
|
|
@ -16,7 +18,7 @@ export const toLysand = (like: Like): LysandLike => {
|
|||
type: "Like",
|
||||
created_at: new Date(like.createdAt).toISOString(),
|
||||
object: (like as any).liked?.uri,
|
||||
uri: `${getConfig().http.base_url}/actions/${like.id}`,
|
||||
uri: `${config.http.base_url}/actions/${like.id}`,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { getConfig } from "~classes/configmanager";
|
||||
import { Worker } from "bullmq";
|
||||
import { client, federationQueue } from "~database/datasource";
|
||||
import {
|
||||
|
|
@ -7,8 +6,9 @@ import {
|
|||
type StatusWithRelations,
|
||||
} from "./Status";
|
||||
import type { User } from "@prisma/client";
|
||||
import { ConfigManager } from "config-manager";
|
||||
|
||||
const config = getConfig();
|
||||
const config = await new ConfigManager({}).getConfig();
|
||||
|
||||
export const federationWorker = new Worker(
|
||||
"federation",
|
||||
|
|
@ -44,7 +44,7 @@ export const federationWorker = new Worker(
|
|||
instanceId: {
|
||||
not: null,
|
||||
},
|
||||
}
|
||||
}
|
||||
: {},
|
||||
// Mentioned users
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
import { getConfig } from "~classes/configmanager";
|
||||
import type { UserWithRelations } from "./User";
|
||||
import {
|
||||
fetchRemoteUser,
|
||||
|
|
@ -29,8 +28,9 @@ import { parse } from "marked";
|
|||
import linkifyStr from "linkify-string";
|
||||
import linkifyHtml from "linkify-html";
|
||||
import { addStausToMeilisearch } from "@meilisearch";
|
||||
import { ConfigManager } from "config-manager";
|
||||
|
||||
const config = getConfig();
|
||||
const config = await new ConfigManager({}).getConfig();
|
||||
|
||||
export const statusAndUserRelations: Prisma.StatusInclude = {
|
||||
author: {
|
||||
|
|
@ -211,7 +211,7 @@ export const fetchFromRemote = async (uri: string): Promise<Status | null> => {
|
|||
? {
|
||||
status: replyStatus,
|
||||
user: (replyStatus as any).author,
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
quote: quotingStatus || undefined,
|
||||
});
|
||||
|
|
@ -349,7 +349,9 @@ export const createNewStatus = async (data: {
|
|||
|
||||
// Get HTML version of content
|
||||
if (data.content_type === "text/markdown") {
|
||||
formattedContent = linkifyHtml(await sanitizeHtml(parse(data.content)));
|
||||
formattedContent = linkifyHtml(
|
||||
await sanitizeHtml(await parse(data.content))
|
||||
);
|
||||
} else if (data.content_type === "text/x.misskeymarkdown") {
|
||||
// Parse as MFM
|
||||
} else {
|
||||
|
|
@ -387,7 +389,7 @@ export const createNewStatus = async (data: {
|
|||
id: attachment,
|
||||
};
|
||||
}),
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
inReplyToPostId: data.reply?.status.id,
|
||||
quotingPostId: data.quote?.id,
|
||||
|
|
@ -480,7 +482,9 @@ export const editStatus = async (
|
|||
|
||||
// Get HTML version of content
|
||||
if (data.content_type === "text/markdown") {
|
||||
formattedContent = linkifyHtml(await sanitizeHtml(parse(data.content)));
|
||||
formattedContent = linkifyHtml(
|
||||
await sanitizeHtml(await parse(data.content))
|
||||
);
|
||||
} else if (data.content_type === "text/x.misskeymarkdown") {
|
||||
// Parse as MFM
|
||||
} else {
|
||||
|
|
@ -519,7 +523,7 @@ export const editStatus = async (
|
|||
id: attachment,
|
||||
};
|
||||
}),
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
mentions: {
|
||||
connect: mentions.map(mention => {
|
||||
|
|
@ -606,15 +610,15 @@ export const statusToAPI = async (
|
|||
quote: status.quotingPost
|
||||
? await statusToAPI(
|
||||
status.quotingPost as unknown as StatusWithRelations
|
||||
)
|
||||
)
|
||||
: null,
|
||||
quote_id: status.quotingPost?.id || undefined,
|
||||
};
|
||||
};
|
||||
|
||||
export const statusToActivityPub = async (
|
||||
status: StatusWithRelations,
|
||||
user?: UserWithRelations
|
||||
/* export const statusToActivityPub = async (
|
||||
status: StatusWithRelations
|
||||
// user?: UserWithRelations
|
||||
): Promise<any> => {
|
||||
// replace any with your ActivityPub type
|
||||
return {
|
||||
|
|
@ -657,7 +661,7 @@ export const statusToActivityPub = async (
|
|||
visibility: "public", // adjust as needed
|
||||
// add more fields as needed
|
||||
};
|
||||
};
|
||||
}; */
|
||||
|
||||
export const statusToLysand = (status: StatusWithRelations): Note => {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import type { ConfigType } from "~classes/configmanager";
|
||||
import { getConfig } from "~classes/configmanager";
|
||||
import type { APIAccount } from "~types/entities/account";
|
||||
import type { User as LysandUser } from "~types/lysand/Object";
|
||||
import { htmlToText } from "html-to-text";
|
||||
|
|
@ -10,6 +8,10 @@ import { addEmojiIfNotExists, emojiToAPI, emojiToLysand } from "./Emoji";
|
|||
import { addInstanceIfNotExists } from "./Instance";
|
||||
import type { APISource } from "~types/entities/source";
|
||||
import { addUserToMeilisearch } from "@meilisearch";
|
||||
import { ConfigManager, type ConfigType } from "config-manager";
|
||||
|
||||
const configManager = new ConfigManager({});
|
||||
const config = await configManager.getConfig();
|
||||
|
||||
export interface AuthData {
|
||||
user: UserWithRelations | null;
|
||||
|
|
@ -201,7 +203,7 @@ export const createNewLocalUser = async (data: {
|
|||
header?: string;
|
||||
admin?: boolean;
|
||||
}) => {
|
||||
const config = getConfig();
|
||||
const config = await configManager.getConfig();
|
||||
|
||||
const keys = await generateUserKeys();
|
||||
|
||||
|
|
@ -344,8 +346,6 @@ export const userToAPI = (
|
|||
user: UserWithRelations,
|
||||
isOwnAccount = false
|
||||
): APIAccount => {
|
||||
const config = getConfig();
|
||||
|
||||
return {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
|
|
@ -373,7 +373,7 @@ export const userToAPI = (
|
|||
header_static: "",
|
||||
acct:
|
||||
user.instance === null
|
||||
? `${user.username}`
|
||||
? user.username
|
||||
: `${user.username}@${user.instance.base_url}`,
|
||||
// TODO: Add these fields
|
||||
limited: false,
|
||||
|
|
@ -424,13 +424,13 @@ export const userToLysand = (user: UserWithRelations): LysandUser => {
|
|||
username: user.username,
|
||||
avatar: [
|
||||
{
|
||||
content: getAvatarUrl(user, getConfig()) || "",
|
||||
content: getAvatarUrl(user, config) || "",
|
||||
content_type: `image/${user.avatar.split(".")[1]}`,
|
||||
},
|
||||
],
|
||||
header: [
|
||||
{
|
||||
content: getHeaderUrl(user, getConfig()) || "",
|
||||
content: getHeaderUrl(user, config) || "",
|
||||
content_type: `image/${user.header.split(".")[1]}`,
|
||||
},
|
||||
],
|
||||
|
|
@ -458,7 +458,7 @@ export const userToLysand = (user: UserWithRelations): LysandUser => {
|
|||
],
|
||||
})),
|
||||
public_key: {
|
||||
actor: `${getConfig().http.base_url}/users/${user.id}`,
|
||||
actor: `${config.http.base_url}/users/${user.id}`,
|
||||
public_key: user.publicKey,
|
||||
},
|
||||
extensions: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue