|
|
@@ -52,8 +52,13 @@ const server = http.createServer(async (req, res) => {
|
|
|
}
|
|
|
|
|
|
if (req.method === "POST" && u.pathname === "/events") {
|
|
|
- let body = "";
|
|
|
- for await (const c of req) body += c;
|
|
|
+ /* 先攒原始Buffer再整体解码:逐块隐式utf8会截断跨块多字节字符;非法UTF-8按GB18030兜底(中文Windows端GBK上报乱码) */
|
|
|
+ const chunks = [];
|
|
|
+ for await (const c of req) chunks.push(c);
|
|
|
+ const raw = Buffer.concat(chunks);
|
|
|
+ let body;
|
|
|
+ try { body = new TextDecoder("utf-8", { fatal: true }).decode(raw); }
|
|
|
+ catch { try { body = new TextDecoder("gb18030", { fatal: true }).decode(raw); } catch { body = raw.toString("utf8"); } }
|
|
|
let d; try { d = JSON.parse(body); } catch { return json(400, { error: "bad json" }); }
|
|
|
if (!d || !d.repo || !d.message) return json(400, { error: "repo/message required" });
|
|
|
const ev = {
|