Skip to content

Commit

Permalink
adding ability to download specific menu versions
Browse files Browse the repository at this point in the history
  • Loading branch information
thelamer committed Dec 27, 2019
1 parent bfee9b5 commit 6cd1ce1
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 26 deletions.
73 changes: 51 additions & 22 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ io.on('connection', function(socket){
io.sockets.in(socket.id).emit('renderdashhook');
});
});
socket.on('upgrademenusdev', function(version){
upgrademenu(version, function(response){
io.sockets.in(socket.id).emit('renderconfighook');
});
});
// When config info is requested send file list to client
socket.on('getconfig', function(){
var local_files = fs.readdirSync('/config/menus/local',{withFileTypes: true}).filter(dirent => !dirent.isDirectory()).map(dirent => dirent.name);
Expand Down Expand Up @@ -149,6 +154,15 @@ io.on('connection', function(socket){
}
io.sockets.in(socket.id).emit('renderlocalhook');
});
// When Dev Browser is requested reach out to github for versions
socket.on('devgetbrowser', async function(){
var api_url = 'https://api.github.com/repos/netbootxyz/netboot.xyz/';
var options = {headers: {'user-agent': 'node.js'}};
var requestPromise = util.promisify(request);
var releases = await requestPromise(api_url + 'releases', options);
var commits = await requestPromise(api_url + 'commits', options);
io.sockets.in(socket.id).emit('devrenderbrowser', JSON.parse(releases.body), JSON.parse(commits.body));
});
});

//// Functions ////
Expand Down Expand Up @@ -178,18 +192,31 @@ async function upgrademenu(version, callback){
fs.unlinkSync(remote_folder + file);
}
// Download files
var download_files = ['menus.tar.gz', 'netboot.xyz-undionly.kpxe', 'netboot.xyz.efi', 'netboot.xyz.kpxe'];
var download_endpoint = 'https://github.com/netbootxyz/netboot.xyz/releases/download/' + version + '/';
var downloads = [];
for (var i in download_files){
var file = download_files[i];
var rom_files = ['netboot.xyz-undionly.kpxe', 'netboot.xyz.efi', 'netboot.xyz.kpxe'];
// This is a commit sha
if (version.length == 40){
var download_endpoint = 'https://s3.amazonaws.com/dev.boot.netboot.xyz/' + version + '/ipxe/';
downloads.push({'url':'https://s3.amazonaws.com/dev.boot.netboot.xyz/' + version + '/menus.tar.gz','path':remote_folder});
}
// This is a regular release
else{
var download_endpoint = 'https://github.com/netbootxyz/netboot.xyz/releases/download/' + version + '/';
downloads.push({'url':download_endpoint + 'menus.tar.gz','path':remote_folder});
}
for (var i in rom_files){
var file = rom_files[i];
var url = download_endpoint + file;
downloads.push({'url':url,'path':remote_folder});
}
// static config for endpoints
downloads.push({'url':'https://raw.githubusercontent.com/netbootxyz/netboot.xyz/' + version +'/endpoints.yml','path':'/config/'});
console.log(downloads);
await downloader(downloads);
var untarcmd = 'tar xf ' + remote_folder + 'menus.tar.gz -C ' + remote_folder;
if (version.length == 40){
var version = 'Development';
}
exec(untarcmd, function (err, stdout) {
fs.unlinkSync(remote_folder + 'menus.tar.gz');
fs.writeFileSync('/config/menuversion.txt', version);
Expand Down Expand Up @@ -237,24 +264,26 @@ async function downloader(downloads){
}
});
await dl.start();
// Part 2 if exists repeat
var requestPromise = util.promisify(request);
var response = await requestPromise(url + '.part2', {method: 'HEAD'});
var s3test = response.headers.server;
if (s3test == 'AmazonS3'){
var dl2 = new DownloaderHelper(url + '.part2', path, dloptions);
dl2.on('end', function(){
console.log('Downloaded ' + url + '.part2' + ' to ' + path);
});
dl2.on('progress', function(stats){
var currentTime = new Date();
var elaspsedTime = currentTime - startTime;
if (elaspsedTime > 500) {
startTime = currentTime;
io.emit('dldata', url, [+i + 1,total], stats);
}
});
await dl2.start();
if ( ! url.includes('s3.amazonaws.com')){
// Part 2 if exists repeat
var requestPromise = util.promisify(request);
var response = await requestPromise(url + '.part2', {method: 'HEAD'});
var s3test = response.headers.server;
if (s3test == 'AmazonS3'){
var dl2 = new DownloaderHelper(url + '.part2', path, dloptions);
dl2.on('end', function(){
console.log('Downloaded ' + url + '.part2' + ' to ' + path);
});
dl2.on('progress', function(stats){
var currentTime = new Date();
var elaspsedTime = currentTime - startTime;
if (elaspsedTime > 500) {
startTime = currentTime;
io.emit('dldata', url, [+i + 1,total], stats);
}
});
await dl2.start();
}
}
}
io.emit('purgestatus');
Expand Down
96 changes: 92 additions & 4 deletions public/js/netbootxyz-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ function upgrademenus(version){
$('#upgradebutton').append('<div class="spinner-grow" style="width: 1rem; height: 1rem;" role="status"><span class="sr-only">Loading...</span></div>');
socket.emit('upgrademenus', version);
}
function upgrademenusdev(version){
$('#configcontent').empty();
$('#configcontent').append('<center><div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status"><span class="sr-only">Loading...</span></div><br><h2>Pulling menus at version requested</h2></center>');
socket.emit('upgrademenusdev', version);
}
// Re-render dash hook
socket.on('renderdashhook', function(){
if($('#upgradebutton').length){
Expand Down Expand Up @@ -137,10 +142,15 @@ socket.on('renderconfig', function(remote_files,local_files,filename,islocal){
<center>\
<h1>Please choose a file to edit<br>Or<br></h1>\
<div class="form-row">\
<div class="col-4"></div>\
<div class="col-2"><input type="text" class="form-control ipxefilename" placeholder="myfile.ipxe"></div>\
<div class="col-2"><button onclick="createipxe()" class="btn btn-primary form-control">Create New</button></div>\
<div class="col-4"></div>\
<div class="col-md-4"></div>\
<div class="col-md-2"><input type="text" class="form-control ipxefilename" placeholder="myfile.ipxe"></div>\
<div class="col-md-2"><button onclick="createipxe()" class="btn btn-primary form-control">Create New</button></div>\
<div class="col-md-4"></div>\
</div><br>\
<div class="form-row">\
<div class="col-md-4"></div>\
<div class="col-md-4"><button onclick="devbrowser()" class="btn btn-outline-info form-control">Menu Development Versions</button></div>\
<div class="col-md-4"></div>\
</div>\
</center>\
</div>\
Expand Down Expand Up @@ -233,6 +243,84 @@ function createipxe(){
$('#pagecontent').append('<center><div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status"><span class="sr-only">Loading...</span></div><br><h2>Creating File</h2></center>');
}
}
// Render edit window
function devbrowser(){
$('#configcontent').empty();
$('#configcontent').append('<center><div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status"><span class="sr-only">Loading...</span></div><br><h2>Getting Remote Development Versions</h2></center>');
socket.emit('devgetbrowser');
}
socket.on('devrenderbrowser', function(releases,commits){
$('#configcontent').empty();
$('#configcontent').append('\
<div class="card-group">\
<div class="card">\
<div class="card-header">\
Development Commits\
</div>\
<div class="card-body">\
<table class="table table-sm" id="commits">\
<thead>\
<tr>\
<th>Commit</th>\
<th></th>\
</tr>\
</thead>\
</table>\
</div>\
</div>\
<div class="card">\
<div class="card-header">\
Releases\
</div>\
<div class="card-body">\
<table class="table table-sm" id="releases" style=".dataTables_filter {display:none;}">\
<thead>\
<tr>\
<th>Release</th>\
<th></th>\
</tr>\
</thead>\
</table>\
</div>\
</div>\
</div>');
var tableoptions = {
"paging": false,
"bInfo" : false,
'sDom': 't',
"order": []
};
$("#commits").dataTable().fnDestroy();
$("#releases").dataTable().fnDestroy();
var commitstable = $('#commits').DataTable(tableoptions);
var releasestable = $('#releases').DataTable(tableoptions);
commitstable.clear();
releasestable.clear();
$.each(releases, function(index,value){
releasestable.row.add(
[
'<a target="_blank" href="' + value.html_url + '">' + value.tag_name + '</a>',
'<span style="float:right;"><button onclick="upgrademenusdev(\'' + value.tag_name + '\')" class="btn btn-outline-success btn-sm">Download</button></span>'
]
);
});
$.each(commits, function(index,value){
commitstable.row.add(
[
'<a target="_blank" href="' + value.html_url + '">' + value.sha + '</a>',
'<span style="float:right;"><button onclick="upgrademenusdev(\'' + value.sha + '\')" class="btn btn-outline-success btn-sm">Download</button></span>'
]
);
});
commitstable.draw();
releasestable.draw();
});
// Re-render menus hook
socket.on('renderconfighook', function(){
if($('#bd-docs-nav').length){
renderconfig();
}
});

//// Local rendering ////
function renderlocal(){
Expand Down

0 comments on commit 6cd1ce1

Please sign in to comment.