First upload version 0.0.1

This commit is contained in:
Neyra
2026-02-05 15:27:49 +08:00
commit 8e9b7201ed
4182 changed files with 593136 additions and 0 deletions

View 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
};

View File

@@ -0,0 +1,6 @@
function getRequestHeader(request, key) {
return request.headers[key];
}
export {
getRequestHeader
};

View File

@@ -0,0 +1,11 @@
function handleResponse(body, status = 200, headers = {}, response) {
if (body === null) {
return false;
}
headers["content-length"] = body.length.toString();
response.writeHead(status, headers).end(body);
return true;
}
export {
handleResponse
};

View File

@@ -0,0 +1,23 @@
import { createLogger } from "../../create-logger.js";
import { createMiddleware } from "../create-middleware.js";
import { handleResponse } from "./handle-response.js";
import { getRequestHeader } from "./get-request-header.js";
import { getPayload } from "./get-payload.js";
function createNodeMiddleware(webhooks, {
path = "/api/github/webhooks",
log = createLogger(),
timeout = 9e3
} = {}) {
return createMiddleware({
handleResponse,
getRequestHeader,
getPayload
})(webhooks, {
path,
log,
timeout
});
}
export {
createNodeMiddleware
};