渠道: 启动自动种Step默认渠道(OMO_STEP_API_KEY) + POST /preset/apply
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user