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 { User } from "@prisma/client";
|
||||||
import type * as Lysand from "lysand-types";
|
import type * as Lysand from "lysand-types";
|
||||||
import { config } from "config-manager";
|
import { config } from "config-manager";
|
||||||
|
import { getUserUri } from "./User";
|
||||||
|
|
||||||
export const objectToInboxRequest = async (
|
export const objectToInboxRequest = async (
|
||||||
object: Lysand.Entity,
|
object: Lysand.Entity,
|
||||||
|
|
@ -8,7 +9,11 @@ export const objectToInboxRequest = async (
|
||||||
userToSendTo: User,
|
userToSendTo: User,
|
||||||
): Promise<Request> => {
|
): Promise<Request> => {
|
||||||
if (!userToSendTo.instanceId || !userToSendTo.endpoints.inbox) {
|
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(
|
const privateKey = await crypto.subtle.importKey(
|
||||||
|
|
@ -51,7 +56,9 @@ export const objectToInboxRequest = async (
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Date: date.toISOString(),
|
Date: date.toISOString(),
|
||||||
Origin: new URL(config.http.base_url).host,
|
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),
|
body: JSON.stringify(object),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import { applicationToAPI } from "./Application";
|
||||||
import { attachmentToAPI, attachmentToLysand } from "./Attachment";
|
import { attachmentToAPI, attachmentToLysand } from "./Attachment";
|
||||||
import { emojiToAPI, emojiToLysand, parseEmojis } from "./Emoji";
|
import { emojiToAPI, emojiToLysand, parseEmojis } from "./Emoji";
|
||||||
import type { UserWithRelations } from "./User";
|
import type { UserWithRelations } from "./User";
|
||||||
import { resolveUser, userToAPI } from "./User";
|
import { getUserUri, userToAPI } from "./User";
|
||||||
import { statusAndUserRelations, userRelations } from "./relations";
|
import { statusAndUserRelations, userRelations } from "./relations";
|
||||||
import { objectToInboxRequest } from "./Federation";
|
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 => {
|
export const statusToLysand = (status: StatusWithRelations): Lysand.Note => {
|
||||||
return {
|
return {
|
||||||
type: "Note",
|
type: "Note",
|
||||||
created_at: new Date(status.createdAt).toISOString(),
|
created_at: new Date(status.createdAt).toISOString(),
|
||||||
id: status.id,
|
id: status.id,
|
||||||
author:
|
author: getUserUri(status.author),
|
||||||
status.author.uri ||
|
uri: getStatusUri(status) ?? "",
|
||||||
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(),
|
|
||||||
content: {
|
content: {
|
||||||
"text/html": {
|
"text/html": {
|
||||||
content: status.content,
|
content: status.content,
|
||||||
|
|
@ -527,8 +526,8 @@ export const statusToLysand = (status: StatusWithRelations): Lysand.Note => {
|
||||||
),
|
),
|
||||||
is_sensitive: status.sensitive,
|
is_sensitive: status.sensitive,
|
||||||
mentions: status.mentions.map((mention) => mention.uri || ""),
|
mentions: status.mentions.map((mention) => mention.uri || ""),
|
||||||
quotes: status.quotingPost?.uri ?? undefined,
|
quotes: getStatusUri(status.quotingPost) ?? undefined,
|
||||||
replies_to: status.inReplyToPost?.uri ?? undefined,
|
replies_to: getStatusUri(status.inReplyToPost) ?? undefined,
|
||||||
subject: status.spoilerText,
|
subject: status.spoilerText,
|
||||||
visibility: status.visibility as Lysand.Visibility,
|
visibility: status.visibility as Lysand.Visibility,
|
||||||
extensions: {
|
extensions: {
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,13 @@ export const resolveUser = async (uri: string) => {
|
||||||
return user;
|
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.
|
* Resolves a WebFinger identifier to a user.
|
||||||
* @param identifier Either a UUID or a username
|
* @param identifier Either a UUID or a username
|
||||||
|
|
@ -513,9 +520,7 @@ export const userToLysand = (user: UserWithRelations): Lysand.User => {
|
||||||
return {
|
return {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
type: "User",
|
type: "User",
|
||||||
uri:
|
uri: getUserUri(user),
|
||||||
user.uri ||
|
|
||||||
new URL(`/users/${user.id}`, config.http.base_url).toString(),
|
|
||||||
bio: {
|
bio: {
|
||||||
"text/html": {
|
"text/html": {
|
||||||
content: user.note,
|
content: user.note,
|
||||||
|
|
@ -612,10 +617,7 @@ export const followRequestToLysand = (
|
||||||
return {
|
return {
|
||||||
type: "Follow",
|
type: "Follow",
|
||||||
id: id,
|
id: id,
|
||||||
author: new URL(
|
author: getUserUri(follower),
|
||||||
`/users/${follower.id}`,
|
|
||||||
config.http.base_url,
|
|
||||||
).toString(),
|
|
||||||
followee: followee.uri,
|
followee: followee.uri,
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
uri: new URL(`/follows/${id}`, config.http.base_url).toString(),
|
uri: new URL(`/follows/${id}`, config.http.base_url).toString(),
|
||||||
|
|
@ -648,10 +650,7 @@ export const followAcceptToLysand = (
|
||||||
config.http.base_url,
|
config.http.base_url,
|
||||||
).toString(),
|
).toString(),
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
follower: new URL(
|
follower: getUserUri(follower),
|
||||||
`/users/${follower.id}`,
|
|
||||||
config.http.base_url,
|
|
||||||
).toString(),
|
|
||||||
uri: new URL(`/follows/${id}`, config.http.base_url).toString(),
|
uri: new URL(`/follows/${id}`, config.http.base_url).toString(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue