feat(panel): 前端 NOT_JSON 自动回传原始响应到 /api/debug/report_bad_json(落 /tmp/overview_client_bad.txt,抓浏览器收到的真实字节)

This commit is contained in:
AskaEth committed 2026-09-02 08:39:29 +08:00
1 parent 57676766c0
commit 524e5d6967
2 files changed
+9

No files matched your search

+8
View File
@@ -5495,6 +5495,14 @@ static int handle(int sock, req_t *r)
if (!strcmp(p, "/api/system/shutdown")) return api_system_action(sock, "shutdown", r);
if (!strcmp(p, "/api/system/ota")) return api_system_action(sock, "ota", r);
if (!strcmp(p, "/api/system/pin-unlock-once")) return api_pin_unlock_once(sock);
if (!strcmp(p, "/api/debug/report_bad_json")) {
/* 前端 NOT_JSON 自动回传浏览器收到的原始字节(抓间歇性破包) */
FILE *df = fopen("/tmp/overview_client_bad.txt", "w");
if (df && r->body && r->body_len) fwrite(r->body, 1, r->body_len, df);
if (df) fclose(df);
panel_log("debug: client bad json captured %zu bytes -> /tmp/overview_client_bad.txt", (size_t)r->body_len);
return send_json(sock, 200, "{\"captured\":true}");
}
if (!strcmp(p, "/api/settings")) return api_settings_batch(sock, r);
if (!strcmp(p, "/api/settings/restore")) return api_settings_restore(sock);
if (!strcmp(p, "/api/theme")) return api_theme_put(sock, r);
+1
View File
@@ -178,6 +178,7 @@
if (!json || typeof json.ok !== 'boolean') {
// 静态服务器返回 HTML / 404 等
dbgErr(method || 'GET', path, 'HTTP', res.status, ms + 'ms', '非 JSON 响应, len=' + text.length, '头:', text.slice(0, 200), '尾:', text.slice(-200));
try { fetch('/api/debug/report_bad_json', { method: 'POST', headers: { 'Content-Type': 'text/plain', 'X-MeowToken': storageGet('meowpanel.token') || '' }, body: text }); } catch (e2) {}
setConn(res.ok ? true : false);
throw { code: 'NOT_JSON', message: '后端返回了非 JSON 响应(HTTP ' + res.status + ')', status: res.status };
}