From 7092c3f9553da13de764565fa48d3e6256b50c05 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Mon, 2 Feb 2026 17:53:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(annotation):=20=E8=B0=83=E6=95=B4=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E7=BC=96=E8=BE=91=E5=99=A8=E5=A4=A7=E5=B0=8F=E9=99=90?= =?UTF-8?q?=E5=88=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将editor_max_text_bytes默认值从2MB改为0,表示不限制 - 更新文本获取服务中的大小检查逻辑,只在max_bytes大于0时进行限制 - 修改错误提示信息中的字节限制显示 - 优化配置参数的条件判断流程 --- runtime/datamate-python/app/core/config.py | 2 +- .../app/module/annotation/service/text_fetcher.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/runtime/datamate-python/app/core/config.py b/runtime/datamate-python/app/core/config.py index 10adb00..df3efa2 100644 --- a/runtime/datamate-python/app/core/config.py +++ b/runtime/datamate-python/app/core/config.py @@ -66,7 +66,7 @@ class Settings(BaseSettings): datamate_backend_base_url: str = "http://datamate-backend:8080/api" # 标注编辑器(Label Studio Editor)相关 - editor_max_text_bytes: int = 2 * 1024 * 1024 # 2MB,避免一次加载超大文本卡死前端 + editor_max_text_bytes: int = 0 # <=0 表示不限制,正数为最大字节数 # 全局设置实例 settings = Settings() diff --git a/runtime/datamate-python/app/module/annotation/service/text_fetcher.py b/runtime/datamate-python/app/module/annotation/service/text_fetcher.py index 8bea9ca..bd24c25 100644 --- a/runtime/datamate-python/app/module/annotation/service/text_fetcher.py +++ b/runtime/datamate-python/app/module/annotation/service/text_fetcher.py @@ -19,23 +19,24 @@ async def fetch_text_content_via_download_api(dataset_id: str, file_id: str) -> resp = await client.get(url) resp.raise_for_status() + max_bytes = settings.editor_max_text_bytes content_length = resp.headers.get("content-length") - if content_length: + if max_bytes > 0 and content_length: try: - if int(content_length) > settings.editor_max_text_bytes: + if int(content_length) > max_bytes: raise HTTPException( status_code=413, - detail=f"文本文件过大,限制 {settings.editor_max_text_bytes} 字节", + detail=f"文本文件过大,限制 {max_bytes} 字节", ) except ValueError: # content-length 非法则忽略,走实际长度判断 pass data = resp.content - if len(data) > settings.editor_max_text_bytes: + if max_bytes > 0 and len(data) > max_bytes: raise HTTPException( status_code=413, - detail=f"文本文件过大,限制 {settings.editor_max_text_bytes} 字节", + detail=f"文本文件过大,限制 {max_bytes} 字节", ) # TEXT POC:默认按 UTF-8 解码,不可解码字符用替换符处理