more rearranging

This commit is contained in:
Moon Man 2023-12-31 00:10:30 -05:00
parent 960c466f97
commit 6ef1b5c9cc
2 changed files with 8 additions and 3 deletions

View File

@ -201,6 +201,7 @@ export const sendAccept = async (user: User, followId: string, follower: string,
};
const payload = JSON.stringify(activity, null, 4);
console.log("Accept payload:", payload);
const init: RequestInit = { method: "POST", body: payload };
const init2 = { privateKey: user.private_key, keyId: getKeyId(user.nickname) };
@ -208,7 +209,7 @@ export const sendAccept = async (user: User, followId: string, follower: string,
const result = await signedFetch(inbox, init, init2);
console.log("response status:", result.status);
const response = await streamToString(result.body as ReadableStream);
console.log("body:", response);
console.log("Response body:", response);
};
export const sendAll = async (keyId: string, privateKey: string, activity: Record<string, any> | string, inboxes: string[]) => {

View File

@ -25,7 +25,7 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si
["Content-Type", `application/ld+json; profile="${CONTEXT}"`]
];
if (signedInit.digest) {
if (signedInit.digest && init.body) {
signedHeaders.push(["Digest", signedInit.digest]);
}
else if (init.body) {
@ -34,6 +34,9 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si
}
else throw "unsupported body type";
}
else {
throw "no body provided";
}
const signer = new Sha256Signer({
privateKey: signedInit.privateKey,
@ -62,7 +65,8 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si
}
else throw "unsupported headers type"; // Lazy.
console.log(init.body, Headers.toString());
console.log("Headers:");
newHeaders.forEach((header) => console.log(header));
return fetch(url, {
...init,