fix: AdminView 保存配置前先加载现有数据

- 避免空对象覆盖数据库中的现有配置
- 保存前先 GET 当前配置
- 合并修改的字段后再 POST
- 确保所有字段都正确保存
This commit is contained in:
2026-10-02 05:42:31 +08:00
parent 4eb423e424
commit 1bc53ae584

View File

@@ -1141,26 +1141,30 @@ async function saveConfig() {
configSaving.value = true configSaving.value = true
configSaveMsg.value = '' configSaveMsg.value = ''
try { try {
const res = await fetch('/api/v1/admin/config')
if (!res.ok) throw new Error(`Failed to load current config: HTTP ${res.status}`)
const currentConfig = await res.json()
const payload = { const payload = {
version: '1.0.0', version: '1.0.0',
vlm_prompts: vlmPrompts.value, vlm_prompts: Object.keys(vlmPrompts.value).length > 0 ? vlmPrompts.value : currentConfig.vlm_prompts || {},
llm_config: llmConfig.value, llm_config: Object.keys(llmConfig.value).length > 0 ? llmConfig.value : currentConfig.llm_config || {},
processor_config: processorConfig.value, processor_config: Object.keys(processorConfig.value).length > 0 ? processorConfig.value : currentConfig.processor_config || {},
filter_config: filterConfig.value, filter_config: Object.keys(filterConfig.value).length > 0 ? filterConfig.value : currentConfig.filter_config || {},
system_config: systemConfig.value, system_config: Object.keys(systemConfig.value).length > 0 ? systemConfig.value : currentConfig.system_config || {},
search: { search: {
vlm_min_score: searchConfig.value.vlm_min_score || 0.0, vlm_min_score: searchConfig.value.vlm_min_score || 0.0,
vlm_max_results: searchConfig.value.vlm_max_results || 5, vlm_max_results: searchConfig.value.vlm_max_results || 5,
vlm_output_language: searchConfig.value.vlm_output_language || 'en' vlm_output_language: searchConfig.value.vlm_output_language || 'en'
}, },
} }
const res = await fetch('/api/v1/admin/config', { const saveRes = await fetch('/api/v1/admin/config', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload), body: JSON.stringify(payload),
}) })
if (!res.ok) throw new Error(`HTTP ${res.status}`) if (!saveRes.ok) throw new Error(`HTTP ${saveRes.status}`)
const data = await res.json() const data = await saveRes.json()
configSaveOk.value = true configSaveOk.value = true
configSaveMsg.value = 'Config saved successfully' configSaveMsg.value = 'Config saved successfully'
} catch (e: any) { } catch (e: any) {