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
configSaveMsg.value = ''
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 = {
version: '1.0.0',
vlm_prompts: vlmPrompts.value,
llm_config: llmConfig.value,
processor_config: processorConfig.value,
filter_config: filterConfig.value,
system_config: systemConfig.value,
vlm_prompts: Object.keys(vlmPrompts.value).length > 0 ? vlmPrompts.value : currentConfig.vlm_prompts || {},
llm_config: Object.keys(llmConfig.value).length > 0 ? llmConfig.value : currentConfig.llm_config || {},
processor_config: Object.keys(processorConfig.value).length > 0 ? processorConfig.value : currentConfig.processor_config || {},
filter_config: Object.keys(filterConfig.value).length > 0 ? filterConfig.value : currentConfig.filter_config || {},
system_config: Object.keys(systemConfig.value).length > 0 ? systemConfig.value : currentConfig.system_config || {},
search: {
vlm_min_score: searchConfig.value.vlm_min_score || 0.0,
vlm_max_results: searchConfig.value.vlm_max_results || 5,
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',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})
if (!res.ok) throw new Error(`HTTP ${res.status}`)
const data = await res.json()
if (!saveRes.ok) throw new Error(`HTTP ${saveRes.status}`)
const data = await saveRes.json()
configSaveOk.value = true
configSaveMsg.value = 'Config saved successfully'
} catch (e: any) {