diff --git a/server/routers/base_router.py b/server/routers/base_router.py index 632e4685..ea70877b 100644 --- a/server/routers/base_router.py +++ b/server/routers/base_router.py @@ -28,6 +28,15 @@ async def update_config( config.save() return config.dump_config() +@base.post("/config/update") +async def update_config_item( + items: dict = Body(...), + current_user: User = Depends(get_admin_user) +) -> dict: + config.update(items) + config.save() + return config.dump_config() + @base.post("/restart") async def restart(current_user: User = Depends(get_superadmin_user)): knowledge_base.restart() diff --git a/src/config/__init__.py b/src/config/__init__.py index 38dee3ef..6bc14fdd 100644 --- a/src/config/__init__.py +++ b/src/config/__init__.py @@ -29,6 +29,10 @@ class SimpleConfig(dict): def __dict__(self): return {k: v for k, v in self.items()} + def update(self, other): + for key, value in other.items(): + self[key] = value + class Config(SimpleConfig): diff --git a/web/src/apis/admin_api.js b/web/src/apis/admin_api.js index 8b48d896..10265634 100644 --- a/web/src/apis/admin_api.js +++ b/web/src/apis/admin_api.js @@ -257,14 +257,16 @@ export const systemConfigApi = { return apiGet('/api/config', {}, true) }, + /** - * 更新系统配置 - * @param {Object} config - 配置项 + * 更新某个配置 + * @param {Object} items - 配置项 * @returns {Promise} - 更新结果 */ - updateSystemConfig: async (config) => { + updateConfigItems: async (items) => { checkAdminPermission() - return apiPut('/api/config', config, {}, true) + console.log("updateConfigItems", items) + return apiPost('/api/config/update', items, {}, true) }, /** diff --git a/web/src/stores/config.js b/web/src/stores/config.js index 44496a9e..91b78a54 100644 --- a/web/src/stores/config.js +++ b/web/src/stores/config.js @@ -21,7 +21,21 @@ export const useConfigStore = defineStore('config', () => { function setConfigValue(key, value) { config.value[key] = value - systemConfigApi.updateSystemConfig({ key, value }) + systemConfigApi.updateConfigItems({ [key]: value }) + .then(data => { + console.debug('Success:', data) + setConfig(data) + }) + } + + function setConfigValues(items) { + // 更新本地配置 + for (const key in items) { + config.value[key] = items[key] + } + + // 发送到服务器 + systemConfigApi.updateConfigItems(items) .then(data => { console.debug('Success:', data) setConfig(data) @@ -36,5 +50,5 @@ export const useConfigStore = defineStore('config', () => { }) } - return { config, setConfig, setConfigValue, refreshConfig } + return { config, setConfig, setConfigValue, refreshConfig, setConfigValues } }) \ No newline at end of file diff --git a/web/src/views/SettingView.vue b/web/src/views/SettingView.vue index 0a0fd6ae..f4c32856 100644 --- a/web/src/views/SettingView.vue +++ b/web/src/views/SettingView.vue @@ -92,7 +92,7 @@