Skip to content

Commit

Permalink
in getOrCreateFolder, create parent folders on the way
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Dec 27, 2024
1 parent 23cf696 commit d70de21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client/common/UploadProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -60,7 +60,7 @@ export function ProgressBar(props) {
'X-CSRFToken': settings.csrf_token,
},
body: JSON.stringify({
name: folderName,
relative_path: relativePath,
}),
});
if (response.ok) {
Expand Down
13 changes: 7 additions & 6 deletions finder/admin/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)})

0 comments on commit d70de21

Please sign in to comment.