more rearranging
This commit is contained in:
parent
960c466f97
commit
6ef1b5c9cc
|
@ -201,6 +201,7 @@ export const sendAccept = async (user: User, followId: string, follower: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
const payload = JSON.stringify(activity, null, 4);
|
const payload = JSON.stringify(activity, null, 4);
|
||||||
|
console.log("Accept payload:", payload);
|
||||||
|
|
||||||
const init: RequestInit = { method: "POST", body: payload };
|
const init: RequestInit = { method: "POST", body: payload };
|
||||||
const init2 = { privateKey: user.private_key, keyId: getKeyId(user.nickname) };
|
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);
|
const result = await signedFetch(inbox, init, init2);
|
||||||
console.log("response status:", result.status);
|
console.log("response status:", result.status);
|
||||||
const response = await streamToString(result.body as ReadableStream);
|
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[]) => {
|
export const sendAll = async (keyId: string, privateKey: string, activity: Record<string, any> | string, inboxes: string[]) => {
|
||||||
|
|
|
@ -25,7 +25,7 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si
|
||||||
["Content-Type", `application/ld+json; profile="${CONTEXT}"`]
|
["Content-Type", `application/ld+json; profile="${CONTEXT}"`]
|
||||||
];
|
];
|
||||||
|
|
||||||
if (signedInit.digest) {
|
if (signedInit.digest && init.body) {
|
||||||
signedHeaders.push(["Digest", signedInit.digest]);
|
signedHeaders.push(["Digest", signedInit.digest]);
|
||||||
}
|
}
|
||||||
else if (init.body) {
|
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 "unsupported body type";
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
throw "no body provided";
|
||||||
|
}
|
||||||
|
|
||||||
const signer = new Sha256Signer({
|
const signer = new Sha256Signer({
|
||||||
privateKey: signedInit.privateKey,
|
privateKey: signedInit.privateKey,
|
||||||
|
@ -62,7 +65,8 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si
|
||||||
}
|
}
|
||||||
else throw "unsupported headers type"; // Lazy.
|
else throw "unsupported headers type"; // Lazy.
|
||||||
|
|
||||||
console.log(init.body, Headers.toString());
|
console.log("Headers:");
|
||||||
|
newHeaders.forEach((header) => console.log(header));
|
||||||
|
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
...init,
|
...init,
|
||||||
|
|
Loading…
Reference in New Issue