From 3b1eac7833b116258ffc2d401c7e6e35c0560564 Mon Sep 17 00:00:00 2001 From: CJACK Date: Sun, 1 Feb 2026 19:43:40 +0800 Subject: [PATCH] feat: Implement a new, modern landing page with dynamic styling and feature highlights. --- README.MD | 4 +- app.py | 3 +- routes/admin/auth.py | 19 +- routes/home.py | 254 +++++++++++++++++++------ webui/package.json | 1 + webui/src/App.jsx | 269 +++++++++++++++------------ webui/src/components/LandingPage.jsx | 141 ++++++++++++++ webui/src/main.jsx | 7 +- webui/vite.config.js | 20 +- 9 files changed, 516 insertions(+), 202 deletions(-) create mode 100644 webui/src/components/LandingPage.jsx diff --git a/README.MD b/README.MD index 70459d3..ea35082 100644 --- a/README.MD +++ b/README.MD @@ -32,7 +32,7 @@ [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FCJackHwang%2Fds2api&env=DS2API_ADMIN_KEY&envDescription=管理面板访问密码(必填)&envLink=https%3A%2F%2Fgithub.com%2FCJackHwang%2Fds2api%23环境变量&project-name=ds2api&repository-name=ds2api) 1. 点击上方按钮,填写管理密码 `DS2API_ADMIN_KEY` -2. 部署完成后访问 `/webui` 管理界面 +2. 部署完成后访问 `/admin` 管理界面 3. 添加 DeepSeek 账号和 API Key 4. 点击「同步到 Vercel」保存配置 @@ -105,7 +105,7 @@ curl https://your-domain.com/v1/chat/completions \ | 接口 | 说明 | |-----|------| -| `GET /webui` | 管理界面 | +| `GET /admin` | 管理界面 | | `GET /admin/config` | 获取配置 | | `POST /admin/accounts/test` | 测试单个账号 | | `POST /admin/accounts/test-all` | 批量测试账号 | diff --git a/app.py b/app.py index e3f3556..4c4d70e 100644 --- a/app.py +++ b/app.py @@ -54,8 +54,9 @@ from routes.admin import router as admin_router app.include_router(openai_router) app.include_router(claude_router) -app.include_router(home_router) +# admin_router 必须在 home_router 之前,否则 home.py 的 /admin/{path:path} 会拦截 admin API app.include_router(admin_router) +app.include_router(home_router) # ---------------------------------------------------------------------- diff --git a/routes/admin/auth.py b/routes/admin/auth.py index 01bf2b4..4e855f8 100644 --- a/routes/admin/auth.py +++ b/routes/admin/auth.py @@ -15,8 +15,8 @@ from core.config import logger router = APIRouter() security = HTTPBearer(auto_error=False) -# Admin Key 验证 -ADMIN_KEY = os.getenv("DS2API_ADMIN_KEY", "") +# Admin Key 验证(默认值适用于开发/演示环境,生产环境请务必修改) +ADMIN_KEY = os.getenv("DS2API_ADMIN_KEY", "your-admin-secret-key") # JWT 配置 JWT_SECRET = os.getenv("DS2API_JWT_SECRET", ADMIN_KEY or "ds2api-default-secret") @@ -105,17 +105,6 @@ async def admin_login(request: Request): admin_key = data.get("admin_key", "") expire_hours = data.get("expire_hours", JWT_EXPIRE_HOURS) - # 开发模式:如果没有配置 ADMIN_KEY,允许任意登录 - if not ADMIN_KEY: - logger.warning("[admin_login] 开发模式:未配置 ADMIN_KEY,允许任意登录") - token = create_jwt_token(expire_hours) - return JSONResponse(content={ - "success": True, - "token": token, - "expires_in": expire_hours * 3600, - "warning": "开发模式 - 未配置 ADMIN_KEY" - }) - if admin_key != ADMIN_KEY: raise HTTPException(status_code=401, detail="Invalid admin key") @@ -147,10 +136,6 @@ async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(secur def verify_admin(credentials: HTTPAuthorizationCredentials = Depends(security)): """验证 Admin 权限(支持 JWT 和直接 admin key)""" - # 开发模式:如果没有配置 ADMIN_KEY,允许所有操作 - if not ADMIN_KEY: - return True - if not credentials: raise HTTPException(status_code=401, detail="Authentication required") diff --git a/routes/home.py b/routes/home.py index 2156406..54191d3 100644 --- a/routes/home.py +++ b/routes/home.py @@ -16,117 +16,255 @@ WELCOME_HTML = """ DS2API - DeepSeek to OpenAI API - + + + +
+
+
+
- -

DeepSeek to OpenAI Compatible API

-