mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
common/ had become the backend's library: 30 of its 41 modules were imported by nothing in the frontend, so the name no longer said what belonged there. It now holds only what the frontend or the build imports too; backend-only code moved to server/, flat except for datasets/ (the dataset engine and its readers). The *-db/ dataset directories stay in common/: self-hosting docs and Docker volumes mount those paths. frontend/utils/ keeps its app-wide modules at the root and gains ip/ (IP / ASN shaping and validation), report/ (the report pipeline) and features/ (the pure layer of a single feature). Paths only — no logic changes. The Dockerfile copies server/, and the AGENTS.md files say where a new module goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 lines
1.1 KiB
JavaScript
25 lines
1.1 KiB
JavaScript
// Shared parser for Cloudflare /cdn-cgi/trace responses (key=value lines).
|
|
//
|
|
// Every trace consumer — the getips/ IP sources, SpeedTest, RuleTest — goes
|
|
// through this instead of hand-splitting lines. Values are trimmed because a
|
|
// body that crossed a rewriting middlebox (TLS-decrypting proxy, corporate
|
|
// gateway) can arrive with CRLF line endings, and a trailing "\r" on the ip
|
|
// value would fail IP validation downstream.
|
|
|
|
// Parse a trace body into a { key: value } map. Non-string input yields {}.
|
|
// Each line splits on its first "=" only (values may themselves contain "=");
|
|
// keys and values are trimmed; lines without a key are skipped. Missing keys
|
|
// simply stay absent, so callers read them as undefined.
|
|
export const parseTrace = (text) => {
|
|
const fields = {};
|
|
if (typeof text !== 'string') return fields;
|
|
for (const line of text.split('\n')) {
|
|
const eq = line.indexOf('=');
|
|
if (eq <= 0) continue;
|
|
const key = line.slice(0, eq).trim();
|
|
if (!key) continue;
|
|
fields[key] = line.slice(eq + 1).trim();
|
|
}
|
|
return fields;
|
|
};
|