fix(avatar): 异步知识库索引并修复大文件上传 #16
@@ -17,7 +17,7 @@ UPLOAD_DIR = os.path.abspath(os.getenv("UPLOAD_DIR", os.path.join(BASE_DIR, "upl
|
|||||||
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
||||||
|
|
||||||
ALLOWED_EXT = {".md", ".txt", ".pdf", ".doc", ".docx", ".xlsx"}
|
ALLOWED_EXT = {".md", ".txt", ".pdf", ".doc", ".docx", ".xlsx"}
|
||||||
MAX_UPLOAD_BYTES = 100 * 1024 * 1024
|
MAX_UPLOAD_BYTES = 50 * 1024 * 1024
|
||||||
UPLOAD_CHUNK_BYTES = 1024 * 1024
|
UPLOAD_CHUNK_BYTES = 1024 * 1024
|
||||||
|
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ async def upload_doc(avatar_id: str, file: UploadFile = File(...), authorization
|
|||||||
while chunk := await file.read(UPLOAD_CHUNK_BYTES):
|
while chunk := await file.read(UPLOAD_CHUNK_BYTES):
|
||||||
file_size += len(chunk)
|
file_size += len(chunk)
|
||||||
if file_size > MAX_UPLOAD_BYTES:
|
if file_size > MAX_UPLOAD_BYTES:
|
||||||
raise ValueError("文件不能超过 100MB")
|
raise ValueError("文件不能超过 50MB")
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ def test_upload_rejects_oversize_file_before_queuing_indexing(
|
|||||||
|
|
||||||
payload = response.json()
|
payload = response.json()
|
||||||
assert payload["code"] == 400
|
assert payload["code"] == 400
|
||||||
assert payload["message"] == "文件不能超过 100MB"
|
assert payload["message"] == "文件不能超过 50MB"
|
||||||
enqueue.assert_not_called()
|
enqueue.assert_not_called()
|
||||||
assert not list((tmp_path / context["avatar"].id).glob("*"))
|
assert not list((tmp_path / context["avatar"].id).glob("*"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user