feat: upload - deel 03.02 - Skipp all toegevoegd

This commit is contained in:
kodi
2026-03-13 18:30:10 +01:00
parent 8fe9d0f436
commit 360815498e
13 changed files with 463 additions and 19 deletions
+2 -1
View File
@@ -37,10 +37,11 @@ async def delete(
@router.post("/upload", response_model=UploadResponse)
async def upload(
target_path: str = Form(...),
overwrite: bool = Form(False),
file: UploadFile = File(...),
service: FileOpsService = Depends(get_file_ops_service),
) -> UploadResponse:
return service.upload(target_path=target_path, upload_file=file)
return service.upload(target_path=target_path, upload_file=file, overwrite=overwrite)
@router.get("/view", response_model=ViewResponse)
+3 -2
View File
@@ -140,8 +140,9 @@ class FilesystemAdapter:
"modified": self.modified_iso(path),
}
def write_uploaded_file(self, path: Path, file_stream, chunk_size: int = 1024 * 1024) -> dict:
with path.open("xb") as handle:
def write_uploaded_file(self, path: Path, file_stream, chunk_size: int = 1024 * 1024, overwrite: bool = False) -> dict:
mode = "wb" if overwrite else "xb"
with path.open(mode) as handle:
while True:
chunk = file_stream.read(chunk_size)
if not chunk:
+20 -8
View File
@@ -204,7 +204,7 @@ class FileOpsService:
self._record_history_error(operation="delete", path=path, error=error)
raise error
def upload(self, target_path: str, upload_file) -> UploadResponse:
def upload(self, target_path: str, upload_file, overwrite: bool = False) -> UploadResponse:
destination_relative = None
history_path = target_path
try:
@@ -216,14 +216,26 @@ class FileOpsService:
resolved_destination = self._path_guard.resolve_path(destination_relative)
if resolved_destination.absolute.exists():
raise AppError(
code="already_exists",
message="Target path already exists",
status_code=409,
details={"path": resolved_destination.relative},
)
if not overwrite:
raise AppError(
code="already_exists",
message="Target path already exists",
status_code=409,
details={"path": resolved_destination.relative},
)
if resolved_destination.absolute.is_dir():
raise AppError(
code="type_conflict",
message="Cannot overwrite an existing directory",
status_code=409,
details={"path": resolved_destination.relative},
)
saved = self._filesystem.write_uploaded_file(resolved_destination.absolute, upload_file.file)
saved = self._filesystem.write_uploaded_file(
resolved_destination.absolute,
upload_file.file,
overwrite=overwrite,
)
self._record_history(
operation="upload",
status="completed",