Skip to content

Commit

Permalink
chore: prohibit manually publishing the bot through the API (#370)
Browse files Browse the repository at this point in the history
* chore: prohibit manually publishing the bot through the API

* chore: fix ci
  • Loading branch information
xingwanying authored Sep 11, 2024
1 parent da9c4c3 commit 7e5f9a2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions server/bot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,14 @@ async def create_bot(
bot_data: BotCreateRequest,
user_id: Annotated[str | None, Depends(get_user_id)] = None,
):
blacklist_fields = {"public"}
filtered_bot_data = {
key: value
for key, value in bot_data.model_dump().items()
if key not in blacklist_fields
}
try:
res = await bot_builder(user_id, **bot_data.model_dump())
res = await bot_builder(user_id, **filtered_bot_data)
if not res:
return JSONResponse(
content={"success": False, "errorMessage": "仓库不存在,生成失败"},
Expand Down Expand Up @@ -141,13 +147,14 @@ def update_bot(
):
if not id:
return {"error": "Incomplete parameters", "status": 400}
blacklist_fields = {"public"}

try:
update_fields = {
key: value
for key, value in bot_data.model_dump(exclude_unset=True).items()
if value is not None
if value is not None and key not in blacklist_fields
}

if not update_fields:
return JSONResponse(
content={"success": False, "errorMessage": "No fields to update"},
Expand Down

0 comments on commit 7e5f9a2

Please sign in to comment.