File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
blog/25-08-27/how-to-download-a-github-directory/ex Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 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 ( ) ) ;
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' ) ;
You can’t perform that action at this time.
0 commit comments