Pārlūkot izejas kodu

HUE-6416 [fb] Opening an image file in sends back binary

Enrico Berti 8 gadi atpakaļ
vecāks
revīzija
e8d8a91414

+ 5 - 1
apps/filebrowser/src/filebrowser/templates/display.mako

@@ -78,7 +78,7 @@ ${ fb_components.menubar() }
 
           <!-- ko if: $root.isViewing -->
           <!-- ko if: $root.file().show_download_button -->
-           <li><a href="${url('filebrowser.views.download', path=path_enc)}"><i class="fa fa-download"></i> ${_('Download')}</a></li>
+           <li><a class="pointer" data-bind="click: $root.downloadFile"><i class="fa fa-download"></i> ${_('Download')}</a></li>
           <!-- /ko -->
            <li><a href="${url('filebrowser.views.view', path=dirname_enc)}"><i class="fa fa-file-text"></i> ${_('View file location')}</a></li>
            <li><a class="pointer" data-bind="click: changePage"><i class="fa fa-refresh"></i> ${_('Refresh')}</a></li>
@@ -368,6 +368,10 @@ ${ fb_components.menubar() }
       self.changePage();
     }
 
+    self.downloadFile = function () {
+      location.href = "${url('filebrowser.views.download', path=path_enc)}";
+    };
+
     self.toggleDisables = function () {
       $(".next-page").removeClass("disabled");
       $(".last-page").removeClass("disabled");

+ 15 - 8
desktop/core/src/desktop/templates/hue.mako

@@ -704,15 +704,21 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
                 xhr.setRequestHeader('X-Requested-With', 'Hue');
               },
               dataType: 'html',
-              success: function (response) {
-                window.clearAppIntervals(app);
-                huePubSub.clearAppSubscribers(app);
-                self.extraEmbeddableURLParams('');
-                var r = self.processHeaders(response);
-                if (SKIP_CACHE.indexOf(app) === -1) {
-                  self.embeddable_cache[app] = r;
+              success: function(response, status, xhr){
+                var type = xhr.getResponseHeader('Content-Type');
+                if (type.indexOf('text/') > -1) {
+                  window.clearAppIntervals(app);
+                  huePubSub.clearAppSubscribers(app);
+                  self.extraEmbeddableURLParams('');
+                  var r = self.processHeaders(response);
+                  if (SKIP_CACHE.indexOf(app) === -1) {
+                    self.embeddable_cache[app] = r;
+                  }
+                  $('#embeddable_' + app).html(r);
+                }
+                else {
+                  window.location.href = baseURL;
                 }
-                $('#embeddable_' + app).html(r);
                 self.isLoadingEmbeddable(false);
               },
               error: function (xhr) {
@@ -798,6 +804,7 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
             page('/editor?' + ctx.querystring);
           }},
           { url: '/filebrowser/view=*', app:  'filebrowser' },
+          { url: '/filebrowser/download=*', app:  'filebrowser' },
           { url: '/filebrowser/*', app: function () {
             page('/filebrowser/view=' + DropzoneGlobals.homeDir);
           }},