fix(ingest): rerun_translation 拒绝短新闻
短新闻(API Push)是中文原生,translation_status 固定为 n/a,
不应当走翻译链路。
前端 ArticleDetail.vue 已经在按钮上加了 v-if='isOwner && !isShort'
(commit 3),web UI 上 owner 看不到重译按钮;但 curl 直接调
POST /admin/translation/rerun/{id} 仍能绕过前端触发翻译,
把 status 改 pending 并入队 translate_article。
本 commit 加后端 guard:is_short_news=True 直接返 400,
跟前端形成双保险。
防呆:
- 修法:在 art 找到后、状态字段重置前先 raise
- 影响范围:仅 rerun_translation 路由,其他 rerun 路径不动
- 不需要 schema/迁移
This commit is contained in:
@@ -139,6 +139,14 @@ async def rerun_translation(
|
||||
art = result.scalar_one_or_none()
|
||||
if not art:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, "Article not found")
|
||||
# 短新闻(API Push)是中文原生,无需翻译
|
||||
# 前端"重译"按钮已对短新闻隐藏(v-if="isOwner && !isShort"),
|
||||
# 这里加 guard 是后端兜底,防止有人直接 curl 调接口绕过前端
|
||||
if art.is_short_news:
|
||||
raise HTTPException(
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
"短新闻(API Push)无需翻译,translation_status 固定为 n/a",
|
||||
)
|
||||
art.translation_status = "pending"
|
||||
art.title_zh = None
|
||||
art.body_zh_text = None
|
||||
|
||||
Reference in New Issue
Block a user