mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
ActivityPub work
This commit is contained in:
parent
a9fb39f764
commit
e05dca9fc1
3 changed files with 229 additions and 0 deletions
|
|
@ -76,3 +76,44 @@ export const emojiToLysand = (emoji: Emoji): LysandEmoji => {
|
|||
alt: emoji.alt || undefined,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts the emoji to an ActivityPub object.
|
||||
* @returns The ActivityPub object.
|
||||
*/
|
||||
export const emojiToActivityPub = (emoji: Emoji): any => {
|
||||
// replace any with your ActivityPub Emoji type
|
||||
return {
|
||||
type: "Emoji",
|
||||
name: `:${emoji.shortcode}:`,
|
||||
updated: new Date().toISOString(),
|
||||
icon: {
|
||||
type: "Image",
|
||||
url: emoji.url,
|
||||
mediaType: emoji.content_type,
|
||||
alt: emoji.alt || undefined,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
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,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -612,6 +612,53 @@ export const statusToAPI = async (
|
|||
};
|
||||
};
|
||||
|
||||
export const statusToActivityPub = async (
|
||||
status: StatusWithRelations,
|
||||
user?: UserWithRelations
|
||||
): Promise<any> => {
|
||||
// replace any with your ActivityPub type
|
||||
return {
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://mastodon.social/schemas/litepub-0.1.jsonld",
|
||||
],
|
||||
id: `${config.http.base_url}/users/${status.authorId}/statuses/${status.id}`,
|
||||
type: "Note",
|
||||
summary: status.spoilerText,
|
||||
content: status.content,
|
||||
published: new Date(status.createdAt).toISOString(),
|
||||
url: `${config.http.base_url}/users/${status.authorId}/statuses/${status.id}`,
|
||||
attributedTo: `${config.http.base_url}/users/${status.authorId}`,
|
||||
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
cc: [], // add recipients here
|
||||
sensitive: status.sensitive,
|
||||
attachment: (status.attachments ?? []).map(
|
||||
a => attachmentToActivityPub(a) as ActivityPubAttachment // replace with your function
|
||||
),
|
||||
tag: [], // add tags here
|
||||
replies: {
|
||||
id: `${config.http.base_url}/users/${status.authorId}/statuses/${status.id}/replies`,
|
||||
type: "Collection",
|
||||
totalItems: status._count.replies,
|
||||
},
|
||||
likes: {
|
||||
id: `${config.http.base_url}/users/${status.authorId}/statuses/${status.id}/likes`,
|
||||
type: "Collection",
|
||||
totalItems: status._count.likes,
|
||||
},
|
||||
shares: {
|
||||
id: `${config.http.base_url}/users/${status.authorId}/statuses/${status.id}/shares`,
|
||||
type: "Collection",
|
||||
totalItems: status._count.reblogs,
|
||||
},
|
||||
inReplyTo: status.inReplyToPostId
|
||||
? `${config.http.base_url}/users/${status.inReplyToPost?.authorId}/statuses/${status.inReplyToPostId}`
|
||||
: null,
|
||||
visibility: "public", // adjust as needed
|
||||
// add more fields as needed
|
||||
};
|
||||
};
|
||||
|
||||
export const statusToLysand = (status: StatusWithRelations): Note => {
|
||||
return {
|
||||
type: "Note",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue