Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] Add new /content_summary public api #3620

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

nidhibhatg marked this conversation as resolved.
Show resolved Hide resolved
@error_handler
def content_summary(request, path):
nidhibhatg marked this conversation as resolved.
Show resolved Hide resolved
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)
nidhibhatg marked this conversation as resolved.
Show resolved Hide resolved

try:
stats = request.fs.get_content_summary(path)
nidhibhatg marked this conversation as resolved.
Show resolved Hide resolved
replication_factor = request.fs.stats(path)['replication']
stats.summary.update({'replication': replication_factor})
response['summary'] = stats.summary
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should log e (especially e.message)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception (all cascading calls too) will get added in stack trace when the exception occurs. @JohanAhlen - Should we add a better log message separately?

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
Loading