From 498e617494f405d425cf04e57d1755843d2690a9 Mon Sep 17 00:00:00 2001 From: QQ Date: Thu, 12 Nov 2026 00:01:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20lib/config.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/config.js b/lib/config.js index 963b8e4..f6b0b70 100644 --- a/lib/config.js +++ b/lib/config.js @@ -43,6 +43,34 @@ export function normalizeBaseUrl(value) { return undefined; } } +/** + * A packaged default that was never replaced by a real service. + * + * `cordis.patch.yml` ships `https://your-memory-host/...` so a fresh profile + * boots without touching a production endpoint. Such an address must be shown + * as "未配置服务" — never as a healthy connection. + */ +export function isPlaceholderBaseUrl(value) { + const normalized = normalizeBaseUrl(value); + if (normalized === undefined) + return true; + try { + const host = new URL(normalized).hostname.toLowerCase(); + return host === 'your-memory-host' || host === 'example.com'; + } + catch { + return true; + } +} +/** Service origin of one base URL, or '' when it cannot be parsed. */ +export function originOf(value) { + try { + return new URL(value).origin; + } + catch { + return ''; + } +} /** Clamp a numeric config value into an integer range, else undefined. */ function boundedInt(value, min, max) { if (typeof value !== 'number' || !Number.isFinite(value))