feat: upload - deel 03.02 - Skipp all toegevoegd
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user