From 4ecf9a8cd60a7b872b1bf1d7de79cf10b39f427c Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Sun, 22 Jun 2025 23:07:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 API 路由中新增获取和重新加载系统信息配置的接口。 - 实现信息配置的加载逻辑,并提供默认配置。 - 更新前端以支持动态加载和展示信息配置。 - 修改 Dockerfile,移除代理设置。 --- docker/api.Dockerfile | 3 +- server/routers/base_router.py | 80 ++++++++++++++++++++++- server/utils/auth_middleware.py | 2 + src/static/info.template.yaml | 26 ++++++++ web/public/jnu.svg | 1 + web/src/apis/public_api.js | 15 +++++ web/src/layouts/AppLayout.vue | 11 +++- web/src/main.js | 10 ++- web/src/stores/info.js | 108 ++++++++++++++++++++++++++++++++ web/src/views/HomeView.vue | 24 +++---- 10 files changed, 262 insertions(+), 18 deletions(-) create mode 100644 src/static/info.template.yaml create mode 100644 web/public/jnu.svg create mode 100644 web/src/stores/info.js diff --git a/docker/api.Dockerfile b/docker/api.Dockerfile index d303599b..f9902687 100644 --- a/docker/api.Dockerfile +++ b/docker/api.Dockerfile @@ -35,8 +35,7 @@ COPY ../src /app/src COPY ../server /app/server # 关闭代理设置 -ENV http_proxy="" \ - https_proxy="" +RUN unset http_proxy https_proxy # 同步项目 RUN --mount=type=cache,target=/root/.cache/uv \ diff --git a/server/routers/base_router.py b/server/routers/base_router.py index 48c0290a..616c973e 100644 --- a/server/routers/base_router.py +++ b/server/routers/base_router.py @@ -1,13 +1,63 @@ -from fastapi import Request, Body, Depends +import os +import yaml +from pathlib import Path +from fastapi import Request, Body, Depends, HTTPException from fastapi import APIRouter from src import config, retriever, knowledge_base, graph_base from server.utils.auth_middleware import get_admin_user, get_superadmin_user from server.models.user_model import User +from src.utils.logging_config import logger base = APIRouter() +def load_info_config(): + """加载信息配置文件""" + try: + # 配置文件路径 + config_path = Path("src/static/info.local.yaml") + + # 检查文件是否存在 + if not config_path.exists(): + logger.warning(f"配置文件 {config_path} 不存在,使用默认配置") + return get_default_info_config() + + # 读取配置文件 + with open(config_path, 'r', encoding='utf-8') as file: + config = yaml.safe_load(file) + + # logger.info(f"成功加载信息配置文件: {config_path}") + return config + + except Exception as e: + logger.error(f"加载信息配置文件失败: {e}") + return get_default_info_config() + +def get_default_info_config(): + """获取默认信息配置""" + return { + "organization": { + "name": "江南大学", + "short_name": "语析", + "logo": "/favicon.svg", + "avatar": "/avatar.jpg" + }, + "branding": { + "title": "Yuxi-Know", + "subtitle": "大模型驱动的知识库管理工具", + "description": "结合知识库与知识图谱,提供更准确、更全面的回答" + }, + "features": [ + "📚 灵活知识库", + "🕸️ 知识图谱集成", + "🤖 多模型支持" + ], + "footer": { + "copyright": "© 江南大学 2025 [WIP] v0.12.138" + } + } + @base.get("/") async def route_index(): return {"message": "You Got It!"} @@ -58,4 +108,32 @@ def get_log(current_user: User = Depends(get_admin_user)): log = ''.join(last_lines) return {"log": log, "message": "success", "log_file": LOG_FILE} +@base.get("/info") +async def get_info_config(): + """获取系统信息配置(公开接口,无需认证)""" + try: + config = load_info_config() + return { + "success": True, + "data": config + } + except Exception as e: + logger.error(f"获取信息配置失败: {e}") + raise HTTPException(status_code=500, detail="获取信息配置失败") + +@base.get("/info/reload") +async def reload_info_config(): + """重新加载信息配置(管理员接口)""" + # 注:这里暂时不添加权限验证,后续可以根据需要添加 + try: + config = load_info_config() + return { + "success": True, + "message": "配置重新加载成功", + "data": config + } + except Exception as e: + logger.error(f"重新加载信息配置失败: {e}") + raise HTTPException(status_code=500, detail="重新加载信息配置失败") + diff --git a/server/utils/auth_middleware.py b/server/utils/auth_middleware.py index 6e917a12..d156fa40 100644 --- a/server/utils/auth_middleware.py +++ b/server/utils/auth_middleware.py @@ -18,6 +18,8 @@ PUBLIC_PATHS = [ r"^/api/auth/initialize$", # 初始化系统 r"^/api$", # Health Check r"^/api/login$", # 登录页面 + r"^/api/info$", # 获取系统信息配置 + r"^/api/info/.*$", # 系统信息配置相关接口 ] # 获取数据库会话 diff --git a/src/static/info.template.yaml b/src/static/info.template.yaml new file mode 100644 index 00000000..fcf66311 --- /dev/null +++ b/src/static/info.template.yaml @@ -0,0 +1,26 @@ +# 单位信息配置文件 +# 用于配置网站的基本信息、品牌信息等 +# 修改后需要重启服务生效 + +# 组织信息 +organization: + name: "江南语析" # 完整组织名称 + short_name: "语析" # 简短名称 + logo: "/favicon.svg" # Logo文件路径 + avatar: "/avatar.jpg" # 头像文件路径 + +# 品牌信息 +branding: + title: "Yuxi-Know" # 系统标题 + subtitle: "大模型驱动的知识库管理工具" # 副标题 + description: "结合知识库与知识图谱,提供更准确、更全面的回答" # 描述信息 + +# 功能特性 +features: + - "📚 灵活知识库" + - "🕸️ 知识图谱集成" + - "🤖 多模型支持" + +# 页脚信息 +footer: + copyright: "© 江南语析 2025 [WIP] v0.12.138" diff --git a/web/public/jnu.svg b/web/public/jnu.svg new file mode 100644 index 00000000..262ffff7 --- /dev/null +++ b/web/public/jnu.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/web/src/apis/public_api.js b/web/src/apis/public_api.js index 66cb0412..134de838 100644 --- a/web/src/apis/public_api.js +++ b/web/src/apis/public_api.js @@ -46,6 +46,21 @@ export const configApi = { getConfig: () => apiGet('/api/config'), } +// 系统信息配置API +export const infoApi = { + /** + * 获取系统信息配置 + * @returns {Promise} - 系统信息配置 + */ + getInfoConfig: () => apiGet('/api/info'), + + /** + * 重新加载信息配置 + * @returns {Promise} - 重新加载结果 + */ + reloadInfoConfig: () => apiGet('/api/info/reload') +} + // 健康检查API export const healthApi = { /** diff --git a/web/src/layouts/AppLayout.vue b/web/src/layouts/AppLayout.vue index 4cabbbee..34023249 100644 --- a/web/src/layouts/AppLayout.vue +++ b/web/src/layouts/AppLayout.vue @@ -10,11 +10,13 @@ import { Bot, Waypoints, LibraryBig, MessageSquareMore, Settings } from 'lucide- import { useConfigStore } from '@/stores/config' import { useDatabaseStore } from '@/stores/database' +import { useInfoStore } from '@/stores/info' import DebugComponent from '@/components/DebugComponent.vue' import UserInfoComponent from '@/components/UserInfoComponent.vue' const configStore = useConfigStore() const databaseStore = useDatabaseStore() +const infoStore = useInfoStore() const layoutSettings = reactive({ showDebug: false, @@ -51,7 +53,10 @@ const fetchGithubStars = async () => { } } -onMounted(() => { +onMounted(async () => { + // 加载信息配置 + await infoStore.loadInfoConfig() + // 加载其他配置 getRemoteConfig() getRemoteDatabase() fetchGithubStars() // Fetch GitHub stars on mount @@ -115,8 +120,8 @@ const mainList = [{