You've already forked DataMate
feat(annotation): 调整文本编辑器大小限制配置
- 将editor_max_text_bytes默认值从2MB改为0,表示不限制 - 更新文本获取服务中的大小检查逻辑,只在max_bytes大于0时进行限制 - 修改错误提示信息中的字节限制显示 - 优化配置参数的条件判断流程
This commit is contained in:
@@ -66,7 +66,7 @@ class Settings(BaseSettings):
|
|||||||
datamate_backend_base_url: str = "http://datamate-backend:8080/api"
|
datamate_backend_base_url: str = "http://datamate-backend:8080/api"
|
||||||
|
|
||||||
# 标注编辑器(Label Studio Editor)相关
|
# 标注编辑器(Label Studio Editor)相关
|
||||||
editor_max_text_bytes: int = 2 * 1024 * 1024 # 2MB,避免一次加载超大文本卡死前端
|
editor_max_text_bytes: int = 0 # <=0 表示不限制,正数为最大字节数
|
||||||
|
|
||||||
# 全局设置实例
|
# 全局设置实例
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|||||||
@@ -19,23 +19,24 @@ async def fetch_text_content_via_download_api(dataset_id: str, file_id: str) ->
|
|||||||
resp = await client.get(url)
|
resp = await client.get(url)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
|
max_bytes = settings.editor_max_text_bytes
|
||||||
content_length = resp.headers.get("content-length")
|
content_length = resp.headers.get("content-length")
|
||||||
if content_length:
|
if max_bytes > 0 and content_length:
|
||||||
try:
|
try:
|
||||||
if int(content_length) > settings.editor_max_text_bytes:
|
if int(content_length) > max_bytes:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=413,
|
status_code=413,
|
||||||
detail=f"文本文件过大,限制 {settings.editor_max_text_bytes} 字节",
|
detail=f"文本文件过大,限制 {max_bytes} 字节",
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# content-length 非法则忽略,走实际长度判断
|
# content-length 非法则忽略,走实际长度判断
|
||||||
pass
|
pass
|
||||||
|
|
||||||
data = resp.content
|
data = resp.content
|
||||||
if len(data) > settings.editor_max_text_bytes:
|
if max_bytes > 0 and len(data) > max_bytes:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=413,
|
status_code=413,
|
||||||
detail=f"文本文件过大,限制 {settings.editor_max_text_bytes} 字节",
|
detail=f"文本文件过大,限制 {max_bytes} 字节",
|
||||||
)
|
)
|
||||||
|
|
||||||
# TEXT POC:默认按 UTF-8 解码,不可解码字符用替换符处理
|
# TEXT POC:默认按 UTF-8 解码,不可解码字符用替换符处理
|
||||||
|
|||||||
Reference in New Issue
Block a user