更新 lib/config.js
This commit is contained in:
parent
50d90f30e6
commit
498e617494
|
|
@ -43,6 +43,34 @@ export function normalizeBaseUrl(value) {
|
||||||
return undefined;
|
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. */
|
/** Clamp a numeric config value into an integer range, else undefined. */
|
||||||
function boundedInt(value, min, max) {
|
function boundedInt(value, min, max) {
|
||||||
if (typeof value !== 'number' || !Number.isFinite(value))
|
if (typeof value !== 'number' || !Number.isFinite(value))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue