From ac4b40630baf4afe383f072835f0116e74709768 Mon Sep 17 00:00:00 2001 From: joserobjr Date: Tue, 5 Apr 2022 16:40:53 -0300 Subject: [PATCH] Add feature to allow direct single file download with directFile=1 parameter --- app/home/down-git.js | 22 +++++++++++++--------- app/home/home.js | 5 +++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/home/down-git.js b/app/home/down-git.js index fab3c38..aaf8874 100644 --- a/app/home/down-git.js +++ b/app/home/down-git.js @@ -119,20 +119,24 @@ downGitModule.factory('downGitService', [ progress.totalFiles.val = requestedPromises.length; } - var downloadFile = function (url, progress, toastr) { + var downloadFile = function (url, progress, toastr, directFile) { progress.isProcessing.val=true; progress.downloadedFiles.val = 0; progress.totalFiles.val = 1; - var zip = new JSZip(); + var zip = !directFile? new JSZip() : null; $http.get(url, {responseType: "arraybuffer"}).then(function (file) { progress.downloadedFiles.val = 1; - zip.file(repoInfo.rootName, file.data); - - progress.isProcessing.val=false; - zip.generateAsync({type:"blob"}).then(function(content) { - saveAs(content, repoInfo.downloadFileName+".zip"); - }); + if (directFile) { + progress.isProcessing.val=false; + saveAs(new Blob([file.data]), repoInfo.downloadFileName); + } else { + zip.file(repoInfo.rootName, file.data); + progress.isProcessing.val=false; + zip.generateAsync({type:"blob"}).then(function(content) { + saveAs(content, repoInfo.downloadFileName+".zip"); + }); + } }, function(error) { console.log(error); progress.isProcessing.val=false; @@ -159,7 +163,7 @@ downGitModule.factory('downGitService', [ if(response.data instanceof Array){ downloadDir(progress); }else{ - downloadFile(response.data.download_url, progress, toastr); + downloadFile(response.data.download_url, progress, toastr, parameters.directFile); } }, function(error) { diff --git a/app/home/home.js b/app/home/home.js index 39e7a82..2aea47a 100644 --- a/app/home/home.js +++ b/app/home/home.js @@ -37,12 +37,13 @@ homeModule.config([ if ($routeParams.url) { $scope.url = $routeParams.url; } - + if ($scope.url.match(templateUrl)) { var parameter = { url: $routeParams.url, fileName: $routeParams.fileName, - rootDirectory: $routeParams.rootDirectory + rootDirectory: $routeParams.rootDirectory, + directFile: $routeParams.directFile, }; var progress = { isProcessing: $scope.isProcessing,