渠道: 启动自动种Step默认渠道(OMO_STEP_API_KEY) + POST /preset/apply

This commit is contained in:
zhiqui
2026-11-15 16:45:29 +08:00
parent 195099a214
commit 6aa3559033
3 changed files with 27 additions and 0 deletions
+16
View File
@@ -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)