Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to allow direct single file download with directFile parameter #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions app/home/down-git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions app/home/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down