Prechádzať zdrojové kódy

[api] Add /storage/download public operation

Romain Rigaux 4 rokov pred
rodič
commit
8f364a4128

+ 1 - 7
apps/filebrowser/src/filebrowser/views.py

@@ -216,12 +216,6 @@ def view(request, path):
 
   path = _normalize_path(path)
 
-  if request.path.startswith('/api/') and request.fs is None:
-    request.fs = fsmanager.get_filesystem(request.fs_ref)
-
-    if request.user.is_authenticated and request.fs is not None:
-      request.fs.setuser(request.user.username)
-
   # default_abfs_home is set in jquery.filechooser.js
   if 'default_abfs_home' in request.GET:
     from azure.abfs.__init__ import get_home_dir_for_ABFS
@@ -656,7 +650,7 @@ def stat(request, path):
 
 def content_summary(request, path):
   path = _normalize_path(path)
-  
+
   if not request.fs.exists(path):
     raise Http404(_("File not found: %(path)s") % {'path': escape(path)})
   response = {'status': -1, 'message': '', 'summary': None}

+ 13 - 0
desktop/core/src/desktop/api_public.py

@@ -24,6 +24,7 @@ from notebook.conf import get_ordered_interpreters
 
 from desktop import api2 as desktop_api
 from desktop.auth.backend import rewrite_user
+from desktop.lib import fsmanager
 
 
 @api_view(["POST"])
@@ -132,6 +133,11 @@ def view(request, path):
   django_request = get_django_request(request)
   return filebrowser_views.view(django_request, path)
 
+@api_view(["GET"])
+def storage_download(request, path):
+  django_request = get_django_request(request)
+  return filebrowser_views.download(django_request, path)
+
 
 def _get_interpreter_from_dialect(dialect, user):
   if not dialect:
@@ -163,4 +169,11 @@ def get_django_request(request):
 
   django_request.user = rewrite_user(django_request.user)
 
+  # Workaround ClusterMiddleware not being applied
+  if django_request.path.startswith('/api/') and django_request.fs is None:
+    django_request.fs = fsmanager.get_filesystem(django_request.fs_ref)
+
+    if django_request.user.is_authenticated and django_request.fs is not None:
+      django_request.fs.setuser(django_request.user.username)
+
   return django_request

+ 1 - 0
desktop/core/src/desktop/api_public_urls.py

@@ -76,6 +76,7 @@ urlpatterns += [
 
 urlpatterns += [
   re_path(r'^storage/view=(?P<path>.*)$', api_public.view, name='api_storage_view'),
+  re_path(r'^storage/download=(?P<path>.*)$', api_public.storage_download, name='api_storage_download'),
 ]
 
 # Slack install API for using CORS by default

+ 3 - 1
docs/docs-site/content/developer/api/rest/_index.md

@@ -414,7 +414,9 @@ e.g. ?offset=0&length=204800&compression=none&mode=text
 
 ### Download
 
-    GET http://127.0.0.1:9000/filebrowser/download=s3a://demo-hue/web_log_data/index_data.csv
+    curl -X GET http://127.0.0.1:9000/api/storage/download=/user/hue/weblogs.csv
+
+    curl -X GET http://127.0.0.1:9000/api/storage/download=s3a://demo-hue/web_log_data/index_data.csv
 
 ### Upload