mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat(federation): ⬆️ Upgrade to Versia 0.5
This commit is contained in:
parent
e6c7e8a597
commit
ed9ffe34f4
10 changed files with 34 additions and 28 deletions
|
|
@ -914,6 +914,10 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
|
|||
remote: false,
|
||||
},
|
||||
},
|
||||
collections: {
|
||||
replies: `/notes/${status.id}/replies`,
|
||||
quotes: `/notes/${status.id}/quotes`,
|
||||
},
|
||||
attachments: (status.attachments ?? []).map((attachment) =>
|
||||
new Media(attachment).toVersia(),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ describe("InboxProcessor", () => {
|
|||
let mockSenderInstance: Instance;
|
||||
let mockHeaders: {
|
||||
signature: string;
|
||||
nonce: string;
|
||||
signedAt: Date;
|
||||
authorization?: string;
|
||||
};
|
||||
let processor: InboxProcessor;
|
||||
|
|
@ -115,7 +115,7 @@ describe("InboxProcessor", () => {
|
|||
// Setup basic mock headers
|
||||
mockHeaders = {
|
||||
signature: "test-signature",
|
||||
nonce: "test-nonce",
|
||||
signedAt: new Date(),
|
||||
};
|
||||
|
||||
// Setup basic mock body
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ export class InboxProcessor {
|
|||
*
|
||||
* @param request Request object.
|
||||
* @param body Entity JSON body.
|
||||
* @param sender Sender of the request's instance and key (from X-Signed-By header). Null if request is from a bridge.
|
||||
* @param sender Sender of the request's instance and key (from Versia-Signed-By header). Null if request is from a bridge.
|
||||
* @param headers Various request headers.
|
||||
* @param logger LogTape logger instance.
|
||||
* @param requestIp Request IP address. Grabs it from the Hono context if not provided.
|
||||
|
|
@ -81,7 +81,7 @@ export class InboxProcessor {
|
|||
} | null,
|
||||
private headers: {
|
||||
signature?: string;
|
||||
nonce?: string;
|
||||
signedAt?: Date;
|
||||
authorization?: string;
|
||||
},
|
||||
private logger: Logger = getLogger(["federation", "inbox"]),
|
||||
|
|
@ -108,8 +108,8 @@ export class InboxProcessor {
|
|||
this.sender.key,
|
||||
);
|
||||
|
||||
if (!(this.headers.signature && this.headers.nonce)) {
|
||||
throw new Error("Missing signature or nonce");
|
||||
if (!(this.headers.signature && this.headers.signedAt)) {
|
||||
throw new Error("Missing signature or signature timestamp");
|
||||
}
|
||||
|
||||
// HACK: Making a fake Request object instead of passing the values directly is necessary because otherwise the validation breaks for some unknown reason
|
||||
|
|
@ -117,8 +117,10 @@ export class InboxProcessor {
|
|||
new Request(this.request.url, {
|
||||
method: this.request.method,
|
||||
headers: {
|
||||
"X-Signature": this.headers.signature,
|
||||
"X-Nonce": this.headers.nonce,
|
||||
"Versia-Signature": this.headers.signature,
|
||||
"Versia-Signed-At": (
|
||||
this.headers.signedAt.getTime() / 1000
|
||||
).toString(),
|
||||
},
|
||||
body: this.request.body,
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ export enum InboxJobType {
|
|||
export type InboxJobData = {
|
||||
data: Entity;
|
||||
headers: {
|
||||
"x-signature"?: string;
|
||||
"x-nonce"?: string;
|
||||
"x-signed-by"?: string;
|
||||
"versia-signature"?: string;
|
||||
"versia-signed-at"?: number;
|
||||
"versia-signed-by"?: string;
|
||||
authorization?: string;
|
||||
};
|
||||
request: {
|
||||
|
|
|
|||
|
|
@ -61,13 +61,13 @@ export const getInboxWorker = (): Worker<InboxJobData, void, InboxJobType> =>
|
|||
}
|
||||
|
||||
const {
|
||||
"x-signature": signature,
|
||||
"x-nonce": nonce,
|
||||
"x-signed-by": signedBy,
|
||||
"versia-signature": signature,
|
||||
"versia-signed-at": signedAt,
|
||||
"versia-signed-by": signedBy,
|
||||
} = headers as {
|
||||
"x-signature": string;
|
||||
"x-nonce": string;
|
||||
"x-signed-by": string;
|
||||
"versia-signature": string;
|
||||
"versia-signed-at": number;
|
||||
"versia-signed-by": string;
|
||||
};
|
||||
|
||||
const sender = await User.resolve(new URL(signedBy));
|
||||
|
|
@ -122,7 +122,7 @@ export const getInboxWorker = (): Worker<InboxJobData, void, InboxJobType> =>
|
|||
},
|
||||
{
|
||||
signature,
|
||||
nonce,
|
||||
signedAt: new Date(signedAt * 1000),
|
||||
authorization: undefined,
|
||||
},
|
||||
getLogger(["federation", "inbox"]),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue