From 779c3c04a530933c222d4a65e68c91713e0d1cbd Mon Sep 17 00:00:00 2001 From: binsky Date: Mon, 24 Apr 2023 20:53:01 +0200 Subject: [PATCH] fix mime type recognition regex for file downloads --- js/app/controllers/edit_credential.js | 17 ++--------------- js/vendor/download.js | 8 ++++---- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/js/app/controllers/edit_credential.js b/js/app/controllers/edit_credential.js index 326ba78e..3025a0e5 100644 --- a/js/app/controllers/edit_credential.js +++ b/js/app/controllers/edit_credential.js @@ -221,33 +221,20 @@ }; $scope.fileLoaded = function (file) { - var key; - var _file = { + const key = CredentialService.getSharedKeyFromCredential($scope.storedCredential); + const _file = { filename: file.name, size: file.size, mimetype: file.type, data: file.data }; - if (!$scope.storedCredential.hasOwnProperty('acl') && $scope.storedCredential.hasOwnProperty('shared_key')) { - - if ($scope.storedCredential.shared_key) { - key = EncryptService.decryptString(angular.copy($scope.storedCredential.shared_key)); - } - } - - if ($scope.storedCredential.hasOwnProperty('acl')) { - key = EncryptService.decryptString(angular.copy($scope.storedCredential.acl.shared_key)); - } - - FileService.uploadFile(_file, key).then(function (result) { delete result.file_data; result.filename = EncryptService.decryptString(result.filename, key); $scope.storedCredential.files.push(result); }); - $scope.$digest(); }; diff --git a/js/vendor/download.js b/js/vendor/download.js index 2a7070ac..81820428 100644 --- a/js/vendor/download.js +++ b/js/vendor/download.js @@ -61,7 +61,7 @@ //go ahead and download dataURLs right away - if(/^data\:[\w+\-]+\/[\w+\-]+[,;]/.test(payload)){ + if(/^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(payload)){ if(payload.length > (1024*1024*1.999) && myBlob !== toString ){ payload=dataUrlToBlob(payload); @@ -112,7 +112,7 @@ // handle non-a[download] safari as best we can: if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) { - url=url.replace(/^data:([\w\/\-\+]+)/, defaultMime); + url=url.replace(/^data:([\w\/\-\+\.]+)/, defaultMime); if(!window.open(url)){ // popup blocked, offer direct download: if(confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")){ location.href=url; } } @@ -124,7 +124,7 @@ document.body.appendChild(f); if(!winMode){ // force a mime that will download: - url="data:"+url.replace(/^data:([\w\/\-\+]+)/, defaultMime); + url="data:"+url.replace(/^data:([\w\/\-\+\.]+)/, defaultMime); } f.src=url; setTimeout(function(){ document.body.removeChild(f); }, 333); @@ -159,4 +159,4 @@ } return true; }; /* end download()*/ -})); \ No newline at end of file +}));