attempt to fix mastodon post follow accept

This commit is contained in:
Moon Man 2023-12-30 23:52:29 -05:00
parent c3d57ccbe8
commit f256889224
2 changed files with 9 additions and 6 deletions

View File

@ -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, any> | string, inboxes: string[]) => {

View File

@ -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<Actor | null> => {