From 6aa3559033ea99c2ae06cfef08e87961506a1244 Mon Sep 17 00:00:00 2001 From: zhiqui Date: Sun, 15 Nov 2026 16:45:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=A0=E9=81=93:=20=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=A7=8DStep=E9=BB=98=E8=AE=A4=E6=B8=A0?= =?UTF-8?q?=E9=81=93(OMO=5FSTEP=5FAPI=5FKEY)=20+=20POST=20/preset/apply?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/routers/channels.py | 16 ++++++++++++++++ app/core/config.py | 2 ++ app/main.py | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/app/api/routers/channels.py b/app/api/routers/channels.py index f047500a..4583fffd 100644 --- a/app/api/routers/channels.py +++ b/app/api/routers/channels.py @@ -32,6 +32,22 @@ async def preset(): return STEP_PRESET +@router.post("/preset/apply") +async def apply_preset(user: User = Depends(current_user), db=Depends(get_db)): + """一键把 Step Plan 预设落成渠道(已有同名渠道则跳过)。""" + from ...core.config import settings + rows = await repos.ChannelRepo.visible_to(db, user) + for r in rows: + if r.name == STEP_PRESET["name"]: + return {"applied": False, "reason": "已存在同名渠道"} + c = Channel(name=STEP_PRESET["name"], base_url=STEP_PRESET["base_url"], + api_key_enc=settings.step_api_key or "", models=STEP_PRESET["models"], + owner_id=user.id if not user.is_admin else None, visibility="admin") + db.add(c) + await db.commit() + return {"applied": True, "channel": _view(c)} + + @router.get("") async def list_channels(user: User = Depends(current_user), db=Depends(get_db)): rows = await repos.ChannelRepo.visible_to(db, user) diff --git a/app/core/config.py b/app/core/config.py index d660b731..c915ac28 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -8,6 +8,8 @@ class Settings(BaseSettings): jwt_expire_minutes: int = 60 * 24 * 7 first_admin_user: str = "admin" first_admin_pass: str = "maopaoya-admin" + # 默认 Step Plan 渠道的 key(为空则种渠道但不填 key,到后台补) + step_api_key: str = "" class Config: env_file = ".env" diff --git a/app/main.py b/app/main.py index 9cf4bd7f..3aa8710f 100644 --- a/app/main.py +++ b/app/main.py @@ -38,6 +38,15 @@ async def startup(): password_hash=security.hash_password(settings.first_admin_pass), kdf_salt=salt.hex(), is_admin=True)) await db.commit() + # 默认渠道:空库时种 Step Plan 预设(key 走 OMO_STEP_API_KEY) + from .models.entities import Channel + from .core.config import STEP_PRESET + chans = (await db.execute(__import__('sqlalchemy').select(Channel))).scalars().all() + if not chans: + db.add(Channel(name=STEP_PRESET["name"], base_url=STEP_PRESET["base_url"], + api_key_enc=settings.step_api_key, models=STEP_PRESET["models"], + owner_id=None, visibility="admin")) + await db.commit() @app.exception_handler(Exception)