- Add services/anythingllm-devtools HTTP API (repos + AnythingLLM + RAG) - Rename gitea-issues to git-issues across smart_ide agents and docs - Add projects/builazoo, builazoo README, cron fragment, ssh-config.example - Add ensure-ia-dev-project-link.sh; wrapper delegates smart_ide id - Bump ia_dev submodule (git-issues rename, project symlinks) - Align 4nkaiignore templates; update API index and project docs
26 lines
679 B
TypeScript
26 lines
679 B
TypeScript
import type { IncomingMessage } from "node:http";
|
|
|
|
const MAX_BODY = 1_048_576;
|
|
|
|
export const readJsonBody = async (req: IncomingMessage): Promise<unknown> => {
|
|
const chunks: Buffer[] = [];
|
|
let total = 0;
|
|
for await (const chunk of req) {
|
|
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
total += buf.length;
|
|
if (total > MAX_BODY) {
|
|
throw new Error("Request body too large");
|
|
}
|
|
chunks.push(buf);
|
|
}
|
|
const raw = Buffer.concat(chunks).toString("utf8").trim();
|
|
if (raw.length === 0) {
|
|
return {};
|
|
}
|
|
try {
|
|
return JSON.parse(raw) as unknown;
|
|
} catch (cause) {
|
|
throw new Error("Invalid JSON body", { cause });
|
|
}
|
|
};
|