Skip to content

Commit

Permalink
[api] Add new /mkdir public API (#3597)
Browse files Browse the repository at this point in the history
- Implement a dedicated /mkdir API method tailored for new storage browser.
- This separates the old method for existing filebrowser to not have regressions + much cleaner new method.
  • Loading branch information
Harshg999 authored Jan 22, 2024
1 parent dcbdd01 commit ac97eab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions apps/filebrowser/src/filebrowser/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
# limitations under the License.

import logging
import posixpath

from django.http import HttpResponse
from django.utils.translation import gettext as _

from desktop.lib.django_util import JsonResponse
from desktop.lib import fsmanager
Expand Down Expand Up @@ -80,3 +84,16 @@ def get_filesystems_with_home_dirs(request): # Using as a public API only for no
})

return JsonResponse(filesystems, safe=False)


@error_handler
def mkdir(request):
path = request.POST.get('path')
name = request.POST.get('name')

if name and (posixpath.sep in name or "#" in name):
raise Exception(_("Error creating %s directory. Slashes or hashes are not allowed in directory name." % name))

request.fs.mkdir(request.fs.join(path, name))
return HttpResponse(status=200)

2 changes: 1 addition & 1 deletion desktop/core/src/desktop/api_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def storage_upload_file(request):
@api_view(["POST"])
def storage_mkdir(request):
django_request = get_django_request(request)
return filebrowser_views.mkdir(django_request)
return filebrowser_api.mkdir(django_request)


# Importer
Expand Down

0 comments on commit ac97eab

Please sign in to comment.