diff --git a/client/common/UploadProgress.tsx b/client/common/UploadProgress.tsx index fa4e274aa..9fe915665 100644 --- a/client/common/UploadProgress.tsx +++ b/client/common/UploadProgress.tsx @@ -51,7 +51,7 @@ export function ProgressBar(props) { })(); }, [file]); - async function getOrCreateFolder(folderName: string) { + async function getOrCreateFolder(relativePath: string) { const fetchUrl = `${settings.base_url}${settings.folder_id}/get_or_create_folder`; const response = await fetch(fetchUrl, { method: 'POST', @@ -60,7 +60,7 @@ export function ProgressBar(props) { 'X-CSRFToken': settings.csrf_token, }, body: JSON.stringify({ - name: folderName, + relative_path: relativePath, }), }); if (response.ok) { diff --git a/finder/admin/folder.py b/finder/admin/folder.py index d62d4843e..069e055a5 100644 --- a/finder/admin/folder.py +++ b/finder/admin/folder.py @@ -377,12 +377,13 @@ def add_folder(self, request, folder_id): def get_or_create_folder(self, request, folder_id): if response := self.check_for_valid_post_request(request, folder_id): return response - if not (parent_folder := self.get_object(request, folder_id)): + if not (folder := self.get_object(request, folder_id)): return HttpResponseNotFound(f"Folder {folder_id} not found.") body = json.loads(request.body) - folder, _ = FolderModel.objects.get_or_create( - name=body['name'], - parent=parent_folder, - defaults={'owner': request.user}, - ) + for folder_name in body['relative_path'].split('/'): + folder, _ = FolderModel.objects.get_or_create( + name=folder_name, + parent=folder, + defaults={'owner': request.user}, + ) return JsonResponse({'folder': self.serialize_inode(folder)})