X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2d5c3de5600cd820e783a27e5d9ebceb6847f9c1..3a3fc5ac54a80b62b05f78cf2da0a7b43f4a4380:/apps/workbench/app/assets/javascripts/upload_to_collection.js diff --git a/apps/workbench/app/assets/javascripts/upload_to_collection.js b/apps/workbench/app/assets/javascripts/upload_to_collection.js index 4fc24a24cd..d66be63853 100644 --- a/apps/workbench/app/assets/javascripts/upload_to_collection.js +++ b/apps/workbench/app/assets/javascripts/upload_to_collection.js @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + var app = angular.module('Workbench', ['Arvados']); app.controller('UploadToCollection', UploadToCollection); app.directive('arvUuid', arvUuid); @@ -65,6 +69,7 @@ function UploadToCollection($scope, $filter, $q, $timeout, //////////////////////////////// var keepProxy; + var defaultErrorMessage = 'A network error occurred: either the server was unreachable, or there is a server configuration problem. Please check your browser debug console for a more specific error message (browser security features prevent us from showing the details here).'; function SliceReader(_slice) { var that = this; @@ -117,7 +122,20 @@ function UploadToCollection($scope, $filter, $q, $timeout, // resolve(locator) when the block is accepted by the // proxy. _deferred = $.Deferred(); - goSend(); + if (proxyUriBase().match(/^http:/) && + window.location.origin.match(/^https:/)) { + // In this case, requests will fail, and no ajax + // success/fail handlers will be called (!), which + // will leave our status saying "uploading" and the + // user waiting for something to happen. Better to + // give up now. + _deferred.reject({ + textStatus: 'error', + err: 'There is a server configuration problem. Proxy ' + proxyUriBase() + ' cannot be used from origin ' + window.location.origin + ' due to the browser\'s mixed-content (https/http) policy.' + }); + } else { + goSend(); + } return _deferred.promise(); } function stop() { @@ -283,7 +301,10 @@ function UploadToCollection($scope, $filter, $q, $timeout, } function setProgress(bytesDone) { var kBps; - that.progress = Math.min(100, 100 * bytesDone / that.file.size) + if (that.file.size == 0) + that.progress = 100; + else + that.progress = Math.min(100, 100 * bytesDone / that.file.size); if (bytesDone > _startByte) { kBps = (bytesDone - _startByte) / (Date.now() - _startTime); @@ -391,13 +412,14 @@ function UploadToCollection($scope, $filter, $q, $timeout, return; } + that.state = 'Failed'; that.stateReason = ( (reason.textStatus || 'Error') + (reason.xhr && reason.xhr.options ? (' (from ' + reason.xhr.options.url + ')') : '') + ': ' + - (reason.err || '')); + (reason.err || defaultErrorMessage)); if (reason.xhr && reason.xhr.responseText) that.stateReason += ' -- ' + reason.xhr.responseText; _deferred.reject(reason); @@ -422,11 +444,18 @@ function UploadToCollection($scope, $filter, $q, $timeout, then(function(collection) { var manifestText = ''; $.each(uploads, function(_, upload) { + var locators = upload.locators; + if (locators.length === 0) { + // Every stream must have at least one + // data locator, even if it is zero bytes + // long: + locators = ['d41d8cd98f00b204e9800998ecf8427e+0']; + } filename = ArvadosClient.uniqueNameForManifest( collection.manifest_text, '.', upload.file.name); collection.manifest_text += '. ' + - upload.locators.join(' ') + + locators.join(' ') + ' 0:' + upload.file.size.toString() + ':' + filename + '\n'; @@ -455,11 +484,11 @@ function UploadToCollection($scope, $filter, $q, $timeout, } }). then(_deferredAppend.resolve, - _deferredAppend.reject). + _deferredAppend.reject); + return _deferredAppend.promise(). always(function() { _deferredAppend = null; }); - return _deferredAppend.promise(); } } }