From 5899717494c754b26b2cf7e95a42550343f2dfa3 Mon Sep 17 00:00:00 2001 From: Fabian Vogler Date: Tue, 25 Apr 2023 10:27:20 +1000 Subject: [PATCH] Remove Downloader --- app/index.html | 1 - app/scripts/controllers/delegate_type.js | 2 +- app/scripts/services/Downloader.js | 110 ----------------------- 3 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 app/scripts/services/Downloader.js diff --git a/app/index.html b/app/index.html index b62c53d..87dff83 100755 --- a/app/index.html +++ b/app/index.html @@ -77,7 +77,6 @@ - diff --git a/app/scripts/controllers/delegate_type.js b/app/scripts/controllers/delegate_type.js index a192a0b..f67cc30 100644 --- a/app/scripts/controllers/delegate_type.js +++ b/app/scripts/controllers/delegate_type.js @@ -7,7 +7,7 @@ }); - angular.module('accreditationApp').controller('DelegateTypeCtrl', function ($scope, $state, $stateParams, $http, alert, Downloader, Event, Zone, DelegateType, REST_BASE_URL) { + angular.module('accreditationApp').controller('DelegateTypeCtrl', function ($scope, $state, $stateParams, $http, alert, Event, Zone, DelegateType, REST_BASE_URL) { $scope.event = Event.get({id: $stateParams.eventId}); diff --git a/app/scripts/services/Downloader.js b/app/scripts/services/Downloader.js deleted file mode 100644 index d29b1c1..0000000 --- a/app/scripts/services/Downloader.js +++ /dev/null @@ -1,110 +0,0 @@ -'use strict'; - -angular.module('accreditationApp') - .service('Downloader', function ($http) { - this.handleDownload = function(data, status, headers, defaultFilename) { - var octetStreamMime = 'application/octet-stream'; - - var rqHeaders = headers(); - var contentType = rqHeaders['content-type'] || octetStreamMime; - var filename = rqHeaders['x-filename'] || defaultFilename; - - var saved = false; - try - { - // Try using msSaveBlob if supported - //console.log("Trying saveBlob method ..."); - var blob = new Blob([data], { type: contentType }); - if(navigator.msSaveBlob) - navigator.msSaveBlob(blob, filename); - else { - // Try using other saveBlob implementations, if available - var saveBlob = navigator.webkitSaveBlob || navigator.mozSaveBlob || navigator.saveBlob; - if(saveBlob === undefined) throw "Not supported"; - saveBlob(blob, filename); - } - console.log("saveBlob succeeded"); - saved = true; - } catch(ex) - { - //console.log("saveBlob method failed with the following exception:"); - //console.log(ex); - } - - if(!saved) - { - // Get the blob url creator - var urlCreator = window.URL || window.webkitURL || window.mozURL || window.msURL; - if(urlCreator) - { - // Try to use a download link - var link = document.createElement('a'); - if('download' in link) - { - // Try to simulate a click - try - { - // Prepare a blob URL - //console.log("Trying download link method with simulated click ... content type " + contentType); - var blob = new Blob([data], { type: contentType }); - var url = urlCreator.createObjectURL(blob); - link.setAttribute('href', url); - - // Set the download attribute (Supported in Chrome 14+ / Firefox 20+) - link.setAttribute("download", filename); - - // Simulate clicking the download link - var event = document.createEvent('MouseEvents'); - event.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); - link.dispatchEvent(event); - //console.log("Download link method with simulated click succeeded"); - saved = true; - - } catch(ex) { - //console.log("Download link method with simulated click failed with the following exception:"); - console.log(ex); - } - } - - if(!saved) - { - // Fallback to window.location method - try - { - // Prepare a blob URL - // Use application/octet-stream when using window.location to force download - //console.log("Trying download link method with window.location ..."); - var blob = new Blob([data], { type: contentType }); - var url = urlCreator.createObjectURL(blob); - // use data: url instead of blob - var reader = new FileReader; - reader.onload = function() { - var blobAsDataUrl = reader.result; - window.location = blobAsDataUrl; - }; - reader.readAsDataURL(blob); - console.log("Download link method with window.location succeeded"); - saved = true; - } catch(ex) { - //console.log("Download link method with window.location failed with the following exception:"); - console.log(ex); - } - } - - if (!saved) - { - alert('File could not be downloaded with this web browser'); - } - - } - } - - if(!saved) - { - // Fallback to window.open method - console.log("No methods worked for saving the arraybuffer, using last resort window.open"); - window.open(httpPath, '_blank', ''); - } - } - }); - \ No newline at end of file