Skip to content

Commit 480f7a5

Browse files
save file
1 parent 0fd203f commit 480f7a5

File tree

1 file changed

+6
-3
lines changed
  • blog/25-08-27/how-to-download-a-github-directory/ex

1 file changed

+6
-3
lines changed

blog/25-08-27/how-to-download-a-github-directory/ex/zip.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
var repo = 'stackoverflow';
99
var branch = 'main';
1010
var path = '/auto-login/';
11-
11+
console.log(owner,repo,branch);
1212
if(path[0]=='/')path = path.slice(1);
1313
if(path && path.at(-1)!='/')path += '/';
14-
14+
console.log(path);
15+
1516
var file = `${path.split('/').filter(Boolean).at(-1)||repo}.zip`;
17+
console.log(file);
1618
var zip = new jszip();
1719
var url = `https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}?recursive=true`;
1820
var json = await fetch(url).then(res=>res.json());
@@ -25,13 +27,14 @@
2527
if(item.type=='tree'){
2628
zip.folder(fn);
2729
}else{
30+
console.log(fn,item.size);
2831
var url = `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/${item.path}`;
2932
var blob = await fetch(url).then(res=>res.blob());
3033
zip.file(fn,blob);
3134
}
3235

3336
}));
34-
37+
console.log('done.');
3538
var blob = await zip.generateAsync({type:'blob'});
3639
var url = window.URL.createObjectURL(blob);
3740
var a = document.createElement('a');

0 commit comments

Comments
 (0)