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 解码,不可解码字符用替换符处理