mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-07 07:22:53 +08:00
fix: sidebar clock icon + cron button loading + #35 _normalizeBaseUrl crash
- 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.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user