From daa74621bda21e8dfb51e42bfd521b7176034356 Mon Sep 17 00:00:00 2001 From: thelamer Date: Mon, 9 Dec 2019 22:39:50 +0000 Subject: [PATCH] adding 2 part file downloads and deletion for local files --- app.js | 39 ++++++++++++++++++++++++++++-- public/js/netbootxyz-web.js | 47 ++++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 24 deletions(-) diff --git a/app.js b/app.js index f152198..2acf06b 100644 --- a/app.js +++ b/app.js @@ -13,6 +13,7 @@ var path = require('path'); var readdirp = require('readdirp'); var request = require('request'); var si = require('systeminformation'); +const util = require('util'); var { version } = require('./package.json'); var yaml = require('js-yaml'); @@ -129,6 +130,15 @@ io.on('connection', function(socket){ io.sockets.in(socket.id).emit('renderlocalhook'); }); }); + // When Local deletes are requested purge items + socket.on('deletelocal', function(dlfiles){ + for (var i in dlfiles){ + var file = dlfiles[i]; + fs.unlinkSync('/assets' + file); + console.log('Deleted /assets' + file); + } + io.sockets.in(socket.id).emit('renderlocalhook'); + }); }); //// Functions //// @@ -195,6 +205,7 @@ async function dlremote(dlfiles, callback){ // downloader loop async function downloader(downloads){ + var startTime = new Date(); var total = downloads.length; for (var i in downloads){ var value = downloads[i]; @@ -205,10 +216,34 @@ async function downloader(downloads){ dl.on('end', function(){ console.log('Downloaded ' + url + ' to ' + path); }); - dl.on('progress', function(stats){ - io.emit('dldata', url, [+i + 1,total], stats); + dl.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 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(); + } } io.emit('purgestatus'); } diff --git a/public/js/netbootxyz-web.js b/public/js/netbootxyz-web.js index 4be47dc..9ec5cee 100644 --- a/public/js/netbootxyz-web.js +++ b/public/js/netbootxyz-web.js @@ -222,30 +222,15 @@ function renderlocal(){ socket.on('renderlocal', function(endpoints,localfiles,remotemenuversion){ $('#pagecontent').empty(); $('#pagecontent').append('\ -
\ -
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ -
\
\
\
\ Remote Assets at ' + remotemenuversion + '\ - \ + \ + \ + \ + \ + \
\
\ \ @@ -255,7 +240,11 @@ socket.on('renderlocal', function(endpoints,localfiles,remotemenuversion){
\
\ Local Assets\ - \ + \ + \ + \ + \ + \
\
\
\ @@ -266,7 +255,7 @@ socket.on('renderlocal', function(endpoints,localfiles,remotemenuversion){ $.each(endpoints.endpoints, function( index, value ) { $.each(value.files, function( arrindex, file ) { if (localfiles.includes(value.path + file)){ - $('#localassets').append(''); + $('#localassets').append(''); } else{ $('#remoteassets').append(''); @@ -312,6 +301,20 @@ function dlremote(){ socket.on('renderlocalhook', function(){ renderlocal(); }); +// Delete local files +function deletelocal(){ + var allfiles = $('.localcheck'); + var deletefiles = []; + $.each(allfiles, function( index, value ) { + if($(this).is(":checked")){ + deletefiles.push($(this).val()); + } + }).promise().done(function(){ + if(deletefiles.length != 0){ + socket.emit('deletelocal',deletefiles); + } + }); +} //// Download Status Bars //// socket.on('dldata', function(url, count, stats){
' + index + '' + value.path.split('download/')[1] + file + '
' + index + '' + value.path.split('download/')[1] + file + '
' + index + '' + value.path.split('download/')[1] + file + '