mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 21:21:24 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -1,12 +1,22 @@
|
||||
const CONTROL_UI_AVATAR_PREFIX = "/avatar";
|
||||
|
||||
export function normalizeControlUiBasePath(basePath?: string): string {
|
||||
if (!basePath) return "";
|
||||
if (!basePath) {
|
||||
return "";
|
||||
}
|
||||
let normalized = basePath.trim();
|
||||
if (!normalized) return "";
|
||||
if (!normalized.startsWith("/")) normalized = `/${normalized}`;
|
||||
if (normalized === "/") return "";
|
||||
if (normalized.endsWith("/")) normalized = normalized.slice(0, -1);
|
||||
if (!normalized) {
|
||||
return "";
|
||||
}
|
||||
if (!normalized.startsWith("/")) {
|
||||
normalized = `/${normalized}`;
|
||||
}
|
||||
if (normalized === "/") {
|
||||
return "";
|
||||
}
|
||||
if (normalized.endsWith("/")) {
|
||||
normalized = normalized.slice(0, -1);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
@@ -17,7 +27,9 @@ export function buildControlUiAvatarUrl(basePath: string, agentId: string): stri
|
||||
}
|
||||
|
||||
function looksLikeLocalAvatarPath(value: string): boolean {
|
||||
if (/[\\/]/.test(value)) return true;
|
||||
if (/[\\/]/.test(value)) {
|
||||
return true;
|
||||
}
|
||||
return /\.(png|jpe?g|gif|webp|svg|ico)$/i.test(value);
|
||||
}
|
||||
|
||||
@@ -27,8 +39,12 @@ export function resolveAssistantAvatarUrl(params: {
|
||||
basePath?: string;
|
||||
}): string | undefined {
|
||||
const avatar = params.avatar?.trim();
|
||||
if (!avatar) return undefined;
|
||||
if (/^https?:\/\//i.test(avatar) || /^data:image\//i.test(avatar)) return avatar;
|
||||
if (!avatar) {
|
||||
return undefined;
|
||||
}
|
||||
if (/^https?:\/\//i.test(avatar) || /^data:image\//i.test(avatar)) {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
const basePath = normalizeControlUiBasePath(params.basePath);
|
||||
const baseAvatarPrefix = basePath
|
||||
@@ -37,9 +53,13 @@ export function resolveAssistantAvatarUrl(params: {
|
||||
if (basePath && avatar.startsWith(`${CONTROL_UI_AVATAR_PREFIX}/`)) {
|
||||
return `${basePath}${avatar}`;
|
||||
}
|
||||
if (avatar.startsWith(baseAvatarPrefix)) return avatar;
|
||||
if (avatar.startsWith(baseAvatarPrefix)) {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
if (!params.agentId) return avatar;
|
||||
if (!params.agentId) {
|
||||
return avatar;
|
||||
}
|
||||
if (looksLikeLocalAvatarPath(avatar)) {
|
||||
return buildControlUiAvatarUrl(basePath, params.agentId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user