First upload version 0.0.1
This commit is contained in:
30
node_modules/@octokit/webhooks/dist-src/middleware/node/get-payload.js
generated
vendored
Normal file
30
node_modules/@octokit/webhooks/dist-src/middleware/node/get-payload.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { concatUint8Array } from "../../concat-uint8array.js";
|
||||
const textDecoder = new TextDecoder("utf-8", { fatal: false });
|
||||
const decode = textDecoder.decode.bind(textDecoder);
|
||||
async function getPayload(request) {
|
||||
if (typeof request.body === "object" && "rawBody" in request && request.rawBody instanceof Uint8Array) {
|
||||
return decode(request.rawBody);
|
||||
} else if (typeof request.body === "string") {
|
||||
return request.body;
|
||||
}
|
||||
const payload = await getPayloadFromRequestStream(request);
|
||||
return decode(payload);
|
||||
}
|
||||
function getPayloadFromRequestStream(request) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let data = [];
|
||||
request.on(
|
||||
"error",
|
||||
(error) => reject(new AggregateError([error], error.message))
|
||||
);
|
||||
request.on("data", data.push.bind(data));
|
||||
request.on("end", () => {
|
||||
const result = concatUint8Array(data);
|
||||
queueMicrotask(() => resolve(result));
|
||||
});
|
||||
});
|
||||
}
|
||||
export {
|
||||
getPayload,
|
||||
getPayloadFromRequestStream
|
||||
};
|
||||
Reference in New Issue
Block a user