refactor: share platform file and route helpers

This commit is contained in:
Cita
2026-03-22 22:17:50 +08:00
parent 9290e51ecc
commit 32d7037629
24 changed files with 375 additions and 333 deletions
+3 -15
View File
@@ -1,3 +1,5 @@
import { parseProxyLogMetadata } from '../../../shared/proxyLogMeta.js';
type ComposeProxyLogMessageArgs = {
clientKind?: string | null;
sessionId?: string | null;
@@ -16,21 +18,7 @@ export type ParsedProxyLogMessageMeta = {
};
export function parseProxyLogMessageMeta(rawMessage: string): ParsedProxyLogMessageMeta {
const clientMatch = rawMessage.match(/\[client:([^\]]+)\]/i);
const sessionMatch = rawMessage.match(/\[session:([^\]]+)\]/i);
const downstreamMatch = rawMessage.match(/\[downstream:([^\]]+)\]/i);
const upstreamMatch = rawMessage.match(/\[upstream:([^\]]+)\]/i);
const messageText = rawMessage.replace(
/^\s*(?:\[(?:client|session|downstream|upstream):[^\]]+\]\s*)+/i,
'',
).trim();
return {
clientKind: clientMatch?.[1]?.trim() || null,
sessionId: sessionMatch?.[1]?.trim() || null,
downstreamPath: downstreamMatch?.[1]?.trim() || null,
upstreamPath: upstreamMatch?.[1]?.trim() || null,
messageText,
};
return parseProxyLogMetadata(rawMessage);
}
export function composeProxyLogMessage({