Skip to content

Commit 73eecc2

Browse files
v1.0.02-DownGit
1 parent 2137477 commit 73eecc2

File tree

11 files changed

+514
-0
lines changed

11 files changed

+514
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<h1> <img src="res/images/downgit.png" width="20" height=auto /> dGitFile </h1>
2+
3+
#### Create GitHub Directory Download Link
4+
5+
With this tool you can directly download or create download link to any GitHub public directory.
6+
7+
### Website
8+
9+
[dGitFile ↑](https://francesmaffyvalor.github.io/dGitFile/#/home)
10+
11+
### How to Use?
12+
13+
![dGitFile User Manual](https://raw.githubusercontent.com/samuelbetio/Studio.com/master/MIT.png)
14+
15+
### License
16+
<a rel="license" href="https://opensource.org/licenses/MIT"><img alt="MIT License" src="https://cloud.githubusercontent.com/assets/5456665/18950087/fbe0681a-865f-11e6-9552-e59d038d5913.png" width="60em" height=auto/></a><br/><a href="https://github.com/samuelbetio/dGitFile/blob/master/LICENSE">dGitFile</a> is licensed under <a rel="license" href="https://opensource.org/licenses/MIT">MIT License</a>.

app/app.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***********************************************************
2+
* Developer: Samuel Betio ([email protected]) *
3+
* Website: https://github.com/samuelbetio/DownGit *
4+
* License: MIT License *
5+
***********************************************************/
6+
7+
'use strict';
8+
9+
var siteHeaderText={};
10+
11+
var downGit = angular.module('downGit', [
12+
'ngRoute',
13+
'homeModule',
14+
'toastr',
15+
]);
16+
17+
downGit.config([
18+
'$routeProvider',
19+
20+
function($routeProvider) {
21+
$routeProvider
22+
.when('/', {
23+
redirectTo: '/home',
24+
})
25+
.otherwise({
26+
redirectTo: '/home',
27+
});
28+
}
29+
]);
30+
31+
downGit.config([
32+
'toastrConfig',
33+
34+
function(toastrConfig) {
35+
angular.extend(toastrConfig, {
36+
positionClass: 'toast-bottom-right',
37+
maxOpened: 3,
38+
});
39+
}
40+
]);

app/home/home.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<div class="home">
2+
<div class="text-center">
3+
4+
<div class="vertical-space"></div>
5+
<h1><a href="https://samuelbetio.github.io/DownGit">DownGit</a></h1>
6+
<div class="center-row"></div>
7+
<h4>Create GitHub Directory Download Link</h4>
8+
9+
10+
11+
<div class="vertical-space"></div>
12+
<div class="col-md-6 center-row">
13+
<input name="url" type="url" placeholder="GitHub Directory Link" class="form-control" ng-model="url" ></input>
14+
</div>
15+
<div class="btn-group center-row">
16+
<button type="button" class="btn btn-default" ng-click="createDownLink()">Create Download Link</button>
17+
<a type="button" class="btn btn-default" ng-href="#home?url={{url}}">Download</a>
18+
</div>
19+
20+
21+
22+
<div ng-show="isProcessing.val">
23+
<div class="vertical-space"></div>
24+
<img class="processing-img" src="res/images/processing.gif" />
25+
<p>Downloaded {{downloadedFiles.val}} of {{totalFiles.val}} files</p>
26+
</div>
27+
28+
29+
<div class="col-md-6 center-row" ng-show="downUrl">
30+
<div class="vertical-space"></div>
31+
<textarea class="form-control download-link-box" ng-model="downUrl" ></textarea>
32+
</div>
33+
34+
35+
<div class="vertical-space"></div>
36+
<div class="footer">
37+
<a target="_blank" href="https://github.com/samuelbetio">Samuel Rapana Betio © 2018</a>. All Rights Reserved. <a target="_blank" href="https://github.com/samuelbetio/dGitFile/releases">Release's File</a>
38+
</div>
39+
40+
</div>
41+
</div>

app/home/home.js

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/***********************************************************
2+
* Developer: Samuel Betio ([email protected]) *
3+
* Website: https://github.com/samuelbetio/DownGit *
4+
* License: MIT License *
5+
***********************************************************/
6+
7+
'use strict';
8+
9+
var homeModule = angular.module('homeModule', [
10+
'ngRoute',
11+
]);
12+
13+
homeModule.config([
14+
'$routeProvider',
15+
16+
function ($routeProvider) {
17+
$routeProvider
18+
.when('/home', {
19+
templateUrl: 'app/home/home.html',
20+
controller: [
21+
'$scope',
22+
'$routeParams',
23+
'$location',
24+
'toastr',
25+
'homeService',
26+
27+
function($scope, $routeParams, $location, toastr, homeService){
28+
$scope.downUrl="";
29+
$scope.url="";
30+
$scope.isProcessing={val: false};
31+
$scope.downloadedFiles={val: 0};
32+
$scope.totalFiles={val: 0};
33+
34+
var templateUrl = "github.com";
35+
var downloadUrlPrefix = "https://samuelbetio.github.io/DownGit/#/home?url=";
36+
37+
if($routeParams.url){
38+
$scope.url=$routeParams.url;
39+
}
40+
41+
if($scope.url.match(templateUrl)){
42+
var progress = {isProcessing: $scope.isProcessing,
43+
downloadedFiles: $scope.downloadedFiles,
44+
totalFiles: $scope.totalFiles};
45+
homeService.downloadZippedFiles($scope.url, progress);
46+
}else if($scope.url!=""){
47+
toastr.warning("Invalid URL",{iconClass: 'toast-down'});
48+
}
49+
50+
$scope.createDownLink = function(){
51+
$scope.downUrl="";
52+
53+
if(!$scope.url){
54+
return;
55+
}
56+
57+
if($scope.url.match(templateUrl)){
58+
$scope.downUrl = downloadUrlPrefix + $scope.url;
59+
}else if($scope.url!=""){
60+
toastr.warning("Invalid URL",{iconClass: 'toast-down'});
61+
}
62+
};
63+
64+
65+
}],
66+
});
67+
}
68+
]);
69+
70+
homeModule.factory('homeService', [
71+
'$http',
72+
'$q',
73+
74+
function ($http, $q) {
75+
var urlPrefix = "";
76+
var urlPostfix = "";
77+
78+
var resolveUrl = function(url){
79+
var repoPath = new URL(url).pathname;
80+
var splitPath = repoPath.split("/", 5);
81+
82+
var resolvedUrl = {};
83+
resolvedUrl.author = splitPath[1];
84+
resolvedUrl.repository = splitPath[2];
85+
resolvedUrl.branch = splitPath[4];
86+
resolvedUrl.directoryPath = repoPath.split(resolvedUrl.branch+"/", 2)[1];
87+
88+
return resolvedUrl;
89+
}
90+
91+
var downloadDir = function(resolvedUrl, progress){
92+
progress.isProcessing.val=true;
93+
urlPrefix = "https://api.github.com/repos/"+resolvedUrl.author+
94+
"/"+resolvedUrl.repository+"/contents/";
95+
urlPostfix = "?ref="+resolvedUrl.branch;
96+
97+
var dirPaths = [];
98+
var files = [];
99+
var requestedPromises = [];
100+
101+
dirPaths.push(resolvedUrl.directoryPath);
102+
mapFileAndDirectory(dirPaths, files, requestedPromises, progress, resolvedUrl);
103+
}
104+
105+
var mapFileAndDirectory = function(dirPaths, files, requestedPromises, progress, resolvedUrl){
106+
$http.get(urlPrefix+dirPaths.pop()+urlPostfix).then(function (response){
107+
for (var i=response.data.length-1; i>=0; i--){
108+
if(response.data[i].type=="dir"){
109+
dirPaths.push(response.data[i].path);
110+
}else{
111+
getFile(response.data[i].path, response.data[i].download_url,
112+
files, requestedPromises, progress);
113+
}
114+
}
115+
116+
if(dirPaths.length<=0){
117+
downloadFiles(files, requestedPromises, progress, resolvedUrl);
118+
}else{
119+
mapFileAndDirectory(dirPaths, files, requestedPromises, progress, resolvedUrl);
120+
}
121+
});
122+
}
123+
124+
var downloadFiles = function(files, requestedPromises, progress, resolvedUrl){
125+
var dirSplits = resolvedUrl.directoryPath.split("/");
126+
var downloadFileName = decodeURI(dirSplits[dirSplits.length-1]);
127+
128+
var zip = new JSZip();
129+
$q.all(requestedPromises).then(function(data) {
130+
for(var i=files.length-1; i>=0; i--){
131+
zip.file(downloadFileName+"/"+files[i].path.split(downloadFileName+"/")[1],
132+
files[i].data);
133+
}
134+
135+
progress.isProcessing.val=false;
136+
zip.generateAsync({type:"blob"}).then(function(content) {
137+
saveAs(content, downloadFileName+".zip");
138+
});
139+
});
140+
}
141+
142+
var getFile = function (path, url, files, requestedPromises, progress) {
143+
var promise = $http.get(url, {responseType: "arraybuffer"}).then(function (file){
144+
files.push({path:path, data:file.data});
145+
progress.downloadedFiles.val = files.length;
146+
}, function(error){
147+
console.log(error);
148+
});
149+
requestedPromises.push(promise);
150+
progress.totalFiles.val = requestedPromises.length;
151+
}
152+
153+
return {
154+
downloadZippedFiles: function(url, progress){
155+
var resolvedUrl = resolveUrl(url);
156+
157+
if(!resolvedUrl.directoryPath || resolvedUrl.directoryPath==""){
158+
if(!resolvedUrl.branch || resolvedUrl.branch==""){
159+
resolvedUrl.branch="master";
160+
}
161+
162+
var downloadUrl = "https://github.com/"+resolvedUrl.author+"/"+
163+
resolvedUrl.repository+"/archive/"+resolvedUrl.branch+".zip";
164+
165+
window.location = downloadUrl;
166+
}else {
167+
downloadDir(resolvedUrl, progress);
168+
}
169+
},
170+
};
171+
}
172+
]);
173+

app/site.css

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
body{
2+
font-family: sans-serif, arial;
3+
color: #4A4F64;
4+
}
5+
6+
h1, h2, h3, h4, h5, h6, p{
7+
margin: 0;
8+
}
9+
10+
a{
11+
color: #004d99;
12+
}a:hover{
13+
text-decoration: none;
14+
color: #004d99;
15+
}
16+
17+
/**********************************/
18+
19+
.home .center-row{
20+
float: none;
21+
margin: auto;
22+
padding-bottom: 1em;
23+
}
24+
25+
.home .vertical-space{
26+
float: none;
27+
margin: auto;
28+
padding-bottom: 3em;
29+
}
30+
31+
.home h1 a{
32+
color: #4A4F64;
33+
}.home h1 a:hover{
34+
text-decoration: none;
35+
}
36+
37+
.home .processing-img{
38+
width: 4em;
39+
height: auto;
40+
}
41+
42+
.home .download-link-box{
43+
resize: vertical;
44+
}
45+
46+
.home .footer{
47+
position: fixed;
48+
bottom: 0;
49+
width: 100%;
50+
}
51+
52+
/**********************************/
53+
54+
.toast-down{
55+
background-image: url("../res/images/warning.png") !important;
56+
background-color: #8c8c8c;
57+
}

index.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
<!doctype html>
3+
<html ng-app="downGit">
4+
<head>
5+
6+
<!-------------------------------- META -------------------------------->
7+
8+
<meta charset="utf-8"/>
9+
<meta name="keywords" content="GitHub Directory Link, GitHub Directory, Github Link, GitHub Directory Download"/>
10+
<meta name="description" content="Create GitHub Directory Download Link"/>
11+
<meta name="author" content="Samuel Rapana Betio"/>
12+
13+
14+
15+
16+
<title>DownGit</title>
17+
<link rel="icon" type="image/ico" href="res/images/downgit.png">
18+
19+
20+
<!-------------------------------- LINK -------------------------------->
21+
22+
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous" />
23+
<link href="https://cdnjs.cloudflare.com/ajax/libs/angular-toastr/2.0.0/angular-toastr.min.css" rel="stylesheet"/>
24+
25+
<link href="app/site.css" rel="stylesheet" />
26+
</head>
27+
<body>
28+
29+
<div ng-view class=""></div>
30+
31+
32+
<!-------------------------------- SCRIPT -------------------------------->
33+
34+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
35+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-route.min.js"></script>
36+
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
37+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
38+
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-toastr/2.0.0/angular-toastr.tpls.min.js"></script>
39+
<script src="https://cdn.rawgit.com/Stuk/jszip/v3.0.0/dist/jszip.min.js"></script>
40+
<script src="lib/filesaver.min.js"></script>
41+
42+
<script src="app/app.js"></script>
43+
<script src="app/home/home.js"></script>
44+
</body>
45+
</html>

0 commit comments

Comments
 (0)