From c4bbf09a19da27f6fa2c08e82084d51d8071fb46 Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 28 Jul 2025 13:42:10 +0800 Subject: [PATCH] update /api/common/homepage --- .../admin_service/controllers/init_config.py | 37 +++++++++++++++++++ services/common/config.py | 4 +- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/services/admin_service/controllers/init_config.py b/services/admin_service/controllers/init_config.py index eaa9f60..caa35cd 100644 --- a/services/admin_service/controllers/init_config.py +++ b/services/admin_service/controllers/init_config.py @@ -2,6 +2,7 @@ import logging from fastapi import APIRouter, Depends +import json from sqlalchemy.orm import Session from services.common.database import get_db from services.common.utils.response_utils import ResponseUtils @@ -19,6 +20,9 @@ from services.admin_service.constants.sys_config_key import ( KEY_LOGIN_GOOGLE_ENABLE, KEY_LOGIN_EMAIL_ENABLE, KEY_LOGIN_EMAIL_MODE, + KEY_FAQ, + KEY_EMBEDED_HTML, + KEY_TOP_NAVIGATION, ) logger = logging.getLogger(__name__) @@ -77,3 +81,36 @@ def get_config(db: Session = Depends(get_db)): except Exception as e: logger.error(f"Failed to get config: {str(e)}") return ResponseUtils.error(message="Failed to get configuration") + +@router.get("/homepage", summary="Get homepage configuration (no login required)", tags=["common"]) +def get_homepage_config(db: Session = Depends(get_db)): + """Get homepage configuration settings without authentication.""" + try: + # Create service instance + sys_config_service = SysConfigService(db) + + # Get homepage config + faq = sys_config_service.get_value_by_key(KEY_FAQ) or "[]" + embeded_html = sys_config_service.get_value_by_key(KEY_EMBEDED_HTML,True) or "{}" + top_navigation = sys_config_service.get_value_by_key(KEY_TOP_NAVIGATION) or "[]" + try: + faq = json.loads(faq) + except json.JSONDecodeError: + return ResponseUtils.error("FAQ配置格式错误") + try: + embeded_html = json.loads(embeded_html) + except json.JSONDecodeError: + return ResponseUtils.error("Embeded HTML配置格式错误") + try: + top_navigation = json.loads(top_navigation) + except json.JSONDecodeError: + return ResponseUtils.error("Top Navigation配置格式错误") + config_data = { + "faq": faq, + "embeded_html": embeded_html, + "top_navigation": top_navigation, + } + return ResponseUtils.success(data=config_data) + except Exception as e: + logger.error(f"Failed to get homepage config: {str(e)}") + return ResponseUtils.error(message="Failed to get configuration") \ No newline at end of file diff --git a/services/common/config.py b/services/common/config.py index 00c1039..b167ca3 100644 --- a/services/common/config.py +++ b/services/common/config.py @@ -55,7 +55,6 @@ class Config: "/redoc", "/api/auth/email/send-captcha", "/api/auth/email/sign", - "/api/common/config", "/api/auth/account/sign", "/api/auth/email/send_captcha", "/api/auth/google/sign", @@ -70,5 +69,6 @@ class Config: [path.strip() for path in _env_no_auth_paths.split(",") if path.strip()] if _env_no_auth_paths else _default_no_auth_paths ) NO_AUTH_PREFIX_PATH=[ - "/uploads/" + "/uploads/", + "/api/common/" ]