Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/api/endpoints/douyin_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,38 @@ async def fetch_video_comments_reply(request: Request,
raise HTTPException(status_code=status_code, detail=detail.dict())


# 获取抖音热榜数据
@router.get("/fetch_hot_search_result",
response_model=ResponseModel,
summary="获取抖音热榜数据/Get Douyin hot search data")
Comment on lines +570 to +572
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

💡 路径命名与 PR 标题不一致,且缺少 douyin 前缀可能造成路由语义不清/后续冲突

PR 标题为 add fetch_douyin_hot_search_result endpoint,但实际路由为 /fetch_hot_search_result。若项目还有其他平台/来源的 hot search,缺少 douyin 前缀可能导致命名冲突或文档语义不清。

建议: 若无历史兼容性要求,考虑将路由改为 /fetch_douyin_hot_search_result 或 /douyin/fetch_hot_search_result,并同步更新 summary/文档。若需要保持兼容,可新增新路由并保留旧路由做别名。

async def fetch_hot_search_result(request: Request):
"""
# [中文]
### 用途:
- 获取抖音热榜数据
### 返回:
- 热榜数据

# [English]
### Purpose:
- Get Douyin hot search data
### Return:
- Hot search data
"""
try:
data = await DouyinWebCrawler.fetch_hot_search_result()
return ResponseModel(code=200,
router=request.url.path,
data=data)
except Exception as e:
status_code = 400
detail = ErrorResponseModel(code=status_code,
router=request.url.path,
params=dict(request.query_params),
)
raise HTTPException(status_code=status_code, detail=detail.dict())
Comment on lines +592 to +598
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

⚠️ 捕获了 Exception 但未记录异常信息,且变量 e 未使用,降低可观测性

当前 except Exception as e 分支中没有使用/记录 e,导致线上排障困难;同时会触发 lint(未使用变量)。建议至少记录异常(logger.exception)或将异常信息(经过脱敏)附加到 detail 中(更推荐日志)。

建议: 在模块内引入 logger 并使用 logger.exception 记录堆栈;同时避免未使用变量告警。

Suggested change
except Exception as e:
status_code = 400
detail = ErrorResponseModel(code=status_code,
router=request.url.path,
params=dict(request.query_params),
)
raise HTTPException(status_code=status_code, detail=detail.dict())
except Exception:
import logging
logging.getLogger(__name__).exception("fetch_hot_search_result failed")
status_code = 400
detail = ErrorResponseModel(code=status_code,
router=request.url.path,
params=dict(request.query_params),
)
raise HTTPException(status_code=status_code, detail=detail.dict())



# 生成真实msToken
@router.get("/generate_real_msToken",
response_model=ResponseModel,
Expand Down