@@ -40,14 +40,14 @@ homeModule.config([
40
40
41
41
if ( $scope . url . match ( templateUrl ) ) {
42
42
var parameter = { url : $routeParams . url ,
43
- fileName : $routeParams . fileName ,
44
- rootDirectory : $routeParams . rootDirectory } ;
43
+ fileName : $routeParams . fileName ,
44
+ rootDirectory : $routeParams . rootDirectory } ;
45
45
var progress = { isProcessing : $scope . isProcessing ,
46
- downloadedFiles : $scope . downloadedFiles ,
47
- totalFiles : $scope . totalFiles } ;
46
+ downloadedFiles : $scope . downloadedFiles ,
47
+ totalFiles : $scope . totalFiles } ;
48
48
homeService . downloadZippedFiles ( parameter , progress ) ;
49
49
} else if ( $scope . url != "" ) {
50
- toastr . warning ( "Invalid URL" , { iconClass : 'toast-down' } ) ;
50
+ toastr . warning ( "Invalid URL" , { iconClass : 'toast-down' } ) ;
51
51
}
52
52
53
53
$scope . createDownLink = function ( ) {
@@ -60,7 +60,7 @@ homeModule.config([
60
60
if ( $scope . url . match ( templateUrl ) ) {
61
61
$scope . downUrl = downloadUrlPrefix + $scope . url ;
62
62
} else if ( $scope . url != "" ) {
63
- toastr . warning ( "Invalid URL" , { iconClass : 'toast-down' } ) ;
63
+ toastr . warning ( "Invalid URL" , { iconClass : 'toast-down' } ) ;
64
64
}
65
65
} ;
66
66
@@ -86,7 +86,7 @@ homeModule.factory('homeService', [
86
86
resolvedUrl . author = splitPath [ 1 ] ;
87
87
resolvedUrl . repository = splitPath [ 2 ] ;
88
88
resolvedUrl . branch = splitPath [ 4 ] ;
89
- resolvedUrl . rootFolderName = splitPath [ splitPath . length - 1 ] ;
89
+ resolvedUrl . rootName = splitPath [ splitPath . length - 1 ] ;
90
90
resolvedUrl . directoryPath = repoPath . substring ( repoPath . indexOf ( splitPath [ 4 ] ) + splitPath [ 4 ] . length + 1 ) ;
91
91
resolvedUrl . urlPrefix = "https://api.github.com/repos/" + resolvedUrl . author +
92
92
"/" + resolvedUrl . repository + "/contents/" ;
@@ -103,12 +103,12 @@ homeModule.factory('homeService', [
103
103
var requestedPromises = [ ] ;
104
104
105
105
if ( ! downloadFileName || downloadFileName == "" ) {
106
- downloadFileName = repoInfo . rootFolderName ;
106
+ downloadFileName = repoInfo . rootName ;
107
107
}
108
108
if ( rootDirectoryName == "false" ) {
109
109
rootDirectoryName = "" ;
110
110
} else if ( ! rootDirectoryName || rootDirectoryName == "" || rootDirectoryName == "true" ) {
111
- rootDirectoryName = repoInfo . rootFolderName + "/" ;
111
+ rootDirectoryName = repoInfo . rootName + "/" ;
112
112
} else {
113
113
rootDirectoryName = rootDirectoryName + "/" ;
114
114
}
@@ -162,23 +162,38 @@ homeModule.factory('homeService', [
162
162
progress . totalFiles . val = requestedPromises . length ;
163
163
}
164
164
165
+ var downloadFile = function ( url ) {
166
+ var zip = new JSZip ( ) ;
167
+ $http . get ( url , { responseType : "arraybuffer" } ) . then ( function ( file ) {
168
+ zip . file ( repoInfo . rootName , file . data ) ;
169
+ zip . generateAsync ( { type :"blob" } ) . then ( function ( content ) {
170
+ saveAs ( content , repoInfo . rootName + ".zip" ) ;
171
+ } ) ;
172
+ } , function ( error ) {
173
+ console . log ( error ) ;
174
+ } ) ;
175
+ }
176
+
165
177
return {
166
178
downloadZippedFiles : function ( parameter , progress ) {
167
- var resolvedUrl = resolveUrl ( parameter . url ) ;
179
+ repoInfo = resolveUrl ( parameter . url ) ;
180
+ downloadFileName = parameter . fileName ;
181
+ rootDirectoryName = parameter . rootDirectory ;
168
182
169
- if ( ! resolvedUrl . directoryPath || resolvedUrl . directoryPath == "" ) {
170
- if ( ! resolvedUrl . branch || resolvedUrl . branch == "" ) {
171
- resolvedUrl . branch = "master" ;
183
+ if ( ! repoInfo . directoryPath || repoInfo . directoryPath == "" ) {
184
+ if ( ! repoInfo . branch || repoInfo . branch == "" ) {
185
+ repoInfo . branch = "master" ;
172
186
}
173
187
174
- var downloadUrl = "https://github.com/" + resolvedUrl . author + "/" +
175
- resolvedUrl . repository + "/archive/" + resolvedUrl . branch + ".zip" ;
188
+ var downloadUrl = "https://github.com/" + repoInfo . author + "/" +
189
+ repoInfo . repository + "/archive/" + repoInfo . branch + ".zip" ;
176
190
177
191
window . location = downloadUrl ;
192
+ } else if ( repoInfo . rootName . indexOf ( "." ) >= 0 ) {
193
+ var downloadUrl = "https://raw.githubusercontent.com/" + repoInfo . author + "/" +
194
+ repoInfo . repository + "/" + repoInfo . branch + "/" + repoInfo . directoryPath ;
195
+ downloadFile ( downloadUrl ) ;
178
196
} else {
179
- downloadFileName = parameter . fileName ;
180
- rootDirectoryName = parameter . rootDirectory ;
181
- repoInfo = resolvedUrl ;
182
197
downloadDir ( progress ) ;
183
198
}
184
199
} ,
0 commit comments