refactor: share non sub2api ops helpers

This commit is contained in:
Codex
2026-06-14 13:03:49 +00:00
parent e3a953fcbb
commit 79d0c58d1e
4 changed files with 38 additions and 87 deletions
+1 -19
View File
@@ -18,6 +18,7 @@ import {
normalizeRemotePath,
numberField,
optionalStringField,
parseEnvFile,
parseOpsApplyOptions,
parseOpsCommonOptions,
readYamlRecord,
@@ -2467,22 +2468,3 @@ function readArchiveCallbackToken(config: WechatArchiveConfig): { sourceRef: str
fingerprint: fingerprintValues({ [config.archiveCallback.tokenKey]: value }, [config.archiveCallback.tokenKey]),
};
}
function parseEnvFile(text: string): Record<string, string> {
const result: Record<string, string> = {};
for (const rawLine of text.split(/\r?\n/u)) {
const line = rawLine.trim();
if (line.length === 0 || line.startsWith("#")) continue;
const eq = line.indexOf("=");
if (eq <= 0) continue;
const key = line.slice(0, eq).trim();
if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(key)) continue;
result[key] = unquoteEnvValue(line.slice(eq + 1).trim());
}
return result;
}
function unquoteEnvValue(value: string): string {
if ((value.startsWith("'") && value.endsWith("'")) || (value.startsWith("\"") && value.endsWith("\""))) return value.slice(1, -1);
return value;
}