Skip to content

Commit

Permalink
[api] Add new /content_summary public api (#3620)
Browse files Browse the repository at this point in the history
* [api] Add new /content_summary public api
  • Loading branch information
nidhibhatg authored Mar 1, 2024
1 parent a46b3b6 commit 55ab28d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
24 changes: 23 additions & 1 deletion apps/filebrowser/src/filebrowser/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from azure.abfs.__init__ import get_home_dir_for_abfs
from aws.s3.s3fs import get_s3_home_directory

from filebrowser.views import _normalize_path

LOG = logging.getLogger()

Expand Down Expand Up @@ -129,4 +130,25 @@ def rename(request):
raise Exception(_('The destination path "%s" already exists.') % dest_path)

request.fs.rename(src_path, dest_path)
return HttpResponse(status=200)
return HttpResponse(status=200)

@error_handler
def content_summary(request, path):
path = _normalize_path(path)
response = {}

if not path:
raise Exception(_('Path parameter is required to fetch content summary.'))

if not request.fs.exists(path):
return JsonResponse(response, status=404)

try:
stats = request.fs.get_content_summary(path)
replication_factor = request.fs.stats(path)['replication']
stats.summary.update({'replication': replication_factor})
response['summary'] = stats.summary
except Exception as e:
raise Exception(_('Failed to fetch content summary for "%s". ') % path)

return JsonResponse(response)
5 changes: 5 additions & 0 deletions desktop/core/src/desktop/api_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ def storage_rename(request):
django_request = get_django_request(request)
return filebrowser_api.rename(django_request)

@api_view(["GET"])
def storage_content_summary(request, path):
django_request = get_django_request(request)
return filebrowser_api.content_summary(django_request, path)

# Importer

@api_view(["POST"])
Expand Down
3 changes: 2 additions & 1 deletion desktop/core/src/desktop/api_public_urls_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
re_path(r'^storage/upload/file/?$', api_public.storage_upload_file, name='storage_upload_file'),
re_path(r'^storage/mkdir$', api_public.storage_mkdir, name='storage_mkdir'),
re_path(r'^storage/touch$', api_public.storage_touch, name='storage_touch'),
re_path(r'^storage/rename$', api_public.storage_rename, name='storage_rename')
re_path(r'^storage/rename$', api_public.storage_rename, name='storage_rename'),
re_path(r'^storage/content_summary=(?P<path>.*)$', api_public.storage_content_summary, name='storage_content_summary'),
]

urlpatterns += [
Expand Down

0 comments on commit 55ab28d

Please sign in to comment.