From f25688922471d4af2328b4015c79a548376b5ef7 Mon Sep 17 00:00:00 2001 From: Moon Man Date: Sat, 30 Dec 2023 23:52:29 -0500 Subject: [PATCH] attempt to fix mastodon post follow accept --- src/activity.ts | 6 +++--- src/net.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/activity.ts b/src/activity.ts index 8d995bc..ecdfc9e 100644 --- a/src/activity.ts +++ b/src/activity.ts @@ -201,14 +201,14 @@ export const sendAccept = async (user: User, followId: string, follower: string, }; const payload = JSON.stringify(activity, null, 4); - const hash = hashDigest(payload); const init: RequestInit = { method: "POST", body: payload }; - const init2 = { hash, privateKey: user.private_key, keyId: getKeyId(user.nickname) }; + const init2 = { privateKey: user.private_key, keyId: getKeyId(user.nickname) }; const result = await signedFetch(inbox, init, init2); console.log("response status:", result.status); - console.log("body:", result.body); + const response = streamToString(result.body as ReadableStream); + console.log("body:", response); }; export const sendAll = async (keyId: string, privateKey: string, activity: Record | string, inboxes: string[]) => { diff --git a/src/net.ts b/src/net.ts index 44d0fa8..d685211 100644 --- a/src/net.ts +++ b/src/net.ts @@ -46,9 +46,9 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si headers: signedHeaders }); - signedHeaders.push(["Signature", signature]); - const newHeaders = new Headers(); + newHeaders.set("Signature", signature); + if (Array.isArray(init.headers) || !init.headers) { for (const header of (init.headers || [])) { if (Array.isArray(header)) @@ -64,7 +64,10 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si } else throw "unsupported headers type"; // Lazy. - return fetch(url, init); + return fetch(url, { + ...init, + headers: newHeaders + }); }; export const getActor = async (actorUrl: string, signedInit: SignedInit): Promise => {