mirror of
https://github.com/versia-pub/server.git
synced 2025-12-07 16:58:20 +01:00
Fix federation bug preventing proper federation
This commit is contained in:
parent
b92d8256a4
commit
1a27be9542
|
|
@ -1,6 +1,7 @@
|
|||
import type { User } from "@prisma/client";
|
||||
import type * as Lysand from "lysand-types";
|
||||
import { config } from "config-manager";
|
||||
import { getUserUri } from "./User";
|
||||
|
||||
export const objectToInboxRequest = async (
|
||||
object: Lysand.Entity,
|
||||
|
|
@ -8,7 +9,11 @@ export const objectToInboxRequest = async (
|
|||
userToSendTo: User,
|
||||
): Promise<Request> => {
|
||||
if (!userToSendTo.instanceId || !userToSendTo.endpoints.inbox) {
|
||||
throw new Error("User has no inbox or is a local user");
|
||||
throw new Error("UserToSendTo has no inbox or is a local user");
|
||||
}
|
||||
|
||||
if (author.instanceId) {
|
||||
throw new Error("Author is a remote user");
|
||||
}
|
||||
|
||||
const privateKey = await crypto.subtle.importKey(
|
||||
|
|
@ -51,7 +56,9 @@ export const objectToInboxRequest = async (
|
|||
"Content-Type": "application/json",
|
||||
Date: date.toISOString(),
|
||||
Origin: new URL(config.http.base_url).host,
|
||||
Signature: `keyId="${author.uri}",algorithm="ed25519",headers="(request-target) host date digest",signature="${signatureBase64}"`,
|
||||
Signature: `keyId="${getUserUri(
|
||||
author,
|
||||
)}",algorithm="ed25519",headers="(request-target) host date digest",signature="${signatureBase64}"`,
|
||||
},
|
||||
body: JSON.stringify(object),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import { applicationToAPI } from "./Application";
|
|||
import { attachmentToAPI, attachmentToLysand } from "./Attachment";
|
||||
import { emojiToAPI, emojiToLysand, parseEmojis } from "./Emoji";
|
||||
import type { UserWithRelations } from "./User";
|
||||
import { resolveUser, userToAPI } from "./User";
|
||||
import { getUserUri, userToAPI } from "./User";
|
||||
import { statusAndUserRelations, userRelations } from "./relations";
|
||||
import { objectToInboxRequest } from "./Federation";
|
||||
|
||||
|
|
@ -497,23 +497,22 @@ export const statusToAPI = async (
|
|||
};
|
||||
};
|
||||
|
||||
export const getStatusUri = (status?: Status | null) => {
|
||||
if (!status) return undefined;
|
||||
|
||||
return (
|
||||
status.uri ||
|
||||
new URL(`/objects/note/${status.id}`, config.http.base_url).toString()
|
||||
);
|
||||
};
|
||||
|
||||
export const statusToLysand = (status: StatusWithRelations): Lysand.Note => {
|
||||
return {
|
||||
type: "Note",
|
||||
created_at: new Date(status.createdAt).toISOString(),
|
||||
id: status.id,
|
||||
author:
|
||||
status.author.uri ||
|
||||
new URL(
|
||||
`/users/${status.author.id}`,
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
uri:
|
||||
status.uri ||
|
||||
new URL(
|
||||
`/objects/note/${status.id}`,
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
author: getUserUri(status.author),
|
||||
uri: getStatusUri(status) ?? "",
|
||||
content: {
|
||||
"text/html": {
|
||||
content: status.content,
|
||||
|
|
@ -527,8 +526,8 @@ export const statusToLysand = (status: StatusWithRelations): Lysand.Note => {
|
|||
),
|
||||
is_sensitive: status.sensitive,
|
||||
mentions: status.mentions.map((mention) => mention.uri || ""),
|
||||
quotes: status.quotingPost?.uri ?? undefined,
|
||||
replies_to: status.inReplyToPost?.uri ?? undefined,
|
||||
quotes: getStatusUri(status.quotingPost) ?? undefined,
|
||||
replies_to: getStatusUri(status.inReplyToPost) ?? undefined,
|
||||
subject: status.spoilerText,
|
||||
visibility: status.visibility as Lysand.Visibility,
|
||||
extensions: {
|
||||
|
|
|
|||
|
|
@ -224,6 +224,13 @@ export const resolveUser = async (uri: string) => {
|
|||
return user;
|
||||
};
|
||||
|
||||
export const getUserUri = (user: User) => {
|
||||
return (
|
||||
user.uri ||
|
||||
new URL(`/users/${user.id}`, config.http.base_url).toString()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolves a WebFinger identifier to a user.
|
||||
* @param identifier Either a UUID or a username
|
||||
|
|
@ -513,9 +520,7 @@ export const userToLysand = (user: UserWithRelations): Lysand.User => {
|
|||
return {
|
||||
id: user.id,
|
||||
type: "User",
|
||||
uri:
|
||||
user.uri ||
|
||||
new URL(`/users/${user.id}`, config.http.base_url).toString(),
|
||||
uri: getUserUri(user),
|
||||
bio: {
|
||||
"text/html": {
|
||||
content: user.note,
|
||||
|
|
@ -612,10 +617,7 @@ export const followRequestToLysand = (
|
|||
return {
|
||||
type: "Follow",
|
||||
id: id,
|
||||
author: new URL(
|
||||
`/users/${follower.id}`,
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
author: getUserUri(follower),
|
||||
followee: followee.uri,
|
||||
created_at: new Date().toISOString(),
|
||||
uri: new URL(`/follows/${id}`, config.http.base_url).toString(),
|
||||
|
|
@ -648,10 +650,7 @@ export const followAcceptToLysand = (
|
|||
config.http.base_url,
|
||||
).toString(),
|
||||
created_at: new Date().toISOString(),
|
||||
follower: new URL(
|
||||
`/users/${follower.id}`,
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
follower: getUserUri(follower),
|
||||
uri: new URL(`/follows/${id}`, config.http.base_url).toString(),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue