feat: add raw stream upload functionality

This commit is contained in:
shiyu
2026-05-16 18:14:52 +08:00
parent 2af2a8756f
commit e3a5317f6f
4 changed files with 106 additions and 15 deletions
+19 -1
View File
@@ -2,7 +2,7 @@ import mimetypes
import re
from urllib.parse import quote
from fastapi import HTTPException, UploadFile
from fastapi import HTTPException, Request, UploadFile
from fastapi.responses import Response
from domain.config import ConfigService
@@ -271,6 +271,24 @@ class VirtualFSRouteMixin(VirtualFSTempLinkMixin):
size = int(result or 0)
return {"uploaded": True, "path": path, "size": size, "overwrite": overwrite}
@classmethod
async def upload_raw_stream(cls, full_path: str, request: Request, overwrite: bool):
full_path = cls._normalize_path(full_path)
if full_path.endswith("/"):
raise HTTPException(400, detail="Path must be a file")
result = await cls.write_file_stream(full_path, request.stream(), overwrite=overwrite)
path = full_path
size = 0
if isinstance(result, dict):
path = result.get("path") or path
size_val = result.get("size")
if isinstance(size_val, int):
size = size_val
else:
size = int(result or 0)
return {"uploaded": True, "path": path, "size": size, "overwrite": overwrite}
@classmethod
async def list_directory(cls, full_path: str, page_num: int, page_size: int, sort_by: str, sort_order: str):
full_path = cls._normalize_path(full_path)