From 01561820be91f5a35ca2b45f0aeada55fcada04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E5=A4=A9?= Date: Wed, 11 Mar 2026 02:03:45 +0800 Subject: [PATCH] fix: sidebar clock icon + cron button loading + #35 _normalizeBaseUrl crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sidebar.js: add clock SVG to ICONS map for 定时任务 nav item - cron.js: add loading feedback to toggle/delete buttons - dev-api.js: extract _normalizeBaseUrl from handlers object to standalone function Fixes #35: 'Cannot read properties of undefined (reading _normalizeBaseUrl)' Root cause: handlers are called as standalone functions via API middleware, so 'this' is undefined. Moving to a standalone function fixes it. --- scripts/dev-api.js | 20 +++++++++++--------- src/components/sidebar.js | 1 + 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/dev-api.js b/scripts/dev-api.js index f24a963..2bc9bd8 100644 --- a/scripts/dev-api.js +++ b/scripts/dev-api.js @@ -992,6 +992,15 @@ const ALWAYS_LOCAL = new Set([ 'assistant_ensure_data_dir', 'assistant_save_image', 'assistant_load_image', 'assistant_delete_image', ]) +// === 工具函数 === + +// 清理 base URL:去掉尾部斜杠和已知端点路径,防止路径重复 +function _normalizeBaseUrl(raw) { + let base = (raw || '').replace(/\/+$/, '') + base = base.replace(/\/(chat\/completions|completions|responses|messages|models)\/?$/, '') + return base.replace(/\/+$/, '') +} + // === API Handlers === const handlers = { @@ -2291,16 +2300,9 @@ const handlers = { return { current, latest: null, update_available: false, source: 'chinese' } }, - // 清理 base URL:去掉尾部斜杠和已知端点路径,防止路径重复 - _normalizeBaseUrl(raw) { - let base = raw.replace(/\/+$/, '') - base = base.replace(/\/(chat\/completions|completions|responses|messages|models)\/?$/, '') - return base.replace(/\/+$/, '') - }, - // 模型测试 async test_model({ baseUrl, apiKey, modelId }) { - const url = `${this._normalizeBaseUrl(baseUrl)}/chat/completions` + const url = `${_normalizeBaseUrl(baseUrl)}/chat/completions` const body = JSON.stringify({ model: modelId, messages: [{ role: 'user', content: 'Hi' }], @@ -2332,7 +2334,7 @@ const handlers = { }, async list_remote_models({ baseUrl, apiKey }) { - const url = `${this._normalizeBaseUrl(baseUrl)}/models` + const url = `${_normalizeBaseUrl(baseUrl)}/models` const headers = {} if (apiKey) headers['Authorization'] = `Bearer ${apiKey}` const controller = new AbortController() diff --git a/src/components/sidebar.js b/src/components/sidebar.js index 42733f1..3bda701 100644 --- a/src/components/sidebar.js +++ b/src/components/sidebar.js @@ -91,6 +91,7 @@ const ICONS = { skills: '', docker: '', channels: '', + clock: '', debug: '', }