Some checks failed
CI / build-check-test (push) Has been cancelled
Restructure local extensions into per-feature directories, split WebUI into backend modules with slash commands and systemd support, and track prompts/skills under .pi/agent for portable Gitea deployment. Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
export function normalizeAvatarUrl(value: unknown): string {
|
|
if (typeof value !== "string") return "";
|
|
const url = value.trim();
|
|
if (!url) return "";
|
|
let parsed: URL;
|
|
try {
|
|
parsed = new URL(url);
|
|
} catch {
|
|
throw new Error(`无效头像链接: ${url}`);
|
|
}
|
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
throw new Error("头像链接仅支持 http 或 https");
|
|
}
|
|
return parsed.toString();
|
|
}
|
|
|
|
export function normalizeConfigKey(key: unknown): string {
|
|
if (typeof key !== "string") throw new Error("配置键必须是字符串");
|
|
const trimmed = key.trim();
|
|
if (!trimmed) throw new Error("配置键不能为空");
|
|
if (trimmed.length > 128) throw new Error("配置键过长");
|
|
if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(trimmed)) {
|
|
throw new Error("配置键格式无效");
|
|
}
|
|
return trimmed;
|
|
}
|
|
|
|
export function normalizeConfigValue(value: unknown): string {
|
|
if (typeof value !== "string") throw new Error("配置值必须是字符串");
|
|
if (value.length > 65536) throw new Error("配置值过长");
|
|
return value;
|
|
}
|