|
|
@ -241,7 +241,7 @@ let binsToUpdate = []; |
|
|
|
* type: |
|
|
|
* params: |
|
|
|
*/ |
|
|
|
shepherd.get('/check-bins', function(req, res, next) { |
|
|
|
shepherd.get('/update/bins/check', function(req, res, next) { |
|
|
|
const rootLocation = path.join(__dirname, '../'); |
|
|
|
|
|
|
|
const successObj = { |
|
|
@ -254,6 +254,13 @@ shepherd.get('/check-bins', function(req, res, next) { |
|
|
|
const _os = os.platform(); |
|
|
|
console.log('checking bins: ' + _os); |
|
|
|
|
|
|
|
cache.io.emit('patch', { |
|
|
|
'patch': { |
|
|
|
'type': 'bins-check', |
|
|
|
'status': 'progress', |
|
|
|
'message': 'checking bins: ' + _os |
|
|
|
} |
|
|
|
}); |
|
|
|
// get list of bins/dlls that can be updated to the latest
|
|
|
|
for (let i = 0; i < latestBins[_os].length; i++) { |
|
|
|
remoteFileSize(remoteBinLocation[_os] + latestBins[_os][i], function(err, remoteBinSize) { |
|
|
@ -270,6 +277,16 @@ shepherd.get('/check-bins', function(req, res, next) { |
|
|
|
'lSize': localBinSize |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (i === latestBins[_os].length - 1) { |
|
|
|
cache.io.emit('patch', { |
|
|
|
'patch': { |
|
|
|
'type': 'bins-check', |
|
|
|
'status': 'done', |
|
|
|
'fileList': binsToUpdate |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
@ -279,7 +296,7 @@ shepherd.get('/check-bins', function(req, res, next) { |
|
|
|
* type: |
|
|
|
* params: |
|
|
|
*/ |
|
|
|
shepherd.get('/update-bins', function(req, res, next) { |
|
|
|
shepherd.get('/update/bins', function(req, res, next) { |
|
|
|
const rootLocation = path.join(__dirname, '../'); |
|
|
|
const _os = os.platform(); |
|
|
|
const successObj = { |
|
|
@ -295,20 +312,43 @@ shepherd.get('/update-bins', function(req, res, next) { |
|
|
|
for (let i = 0; i < binsToUpdate.length; i++) { |
|
|
|
downloadFile({ |
|
|
|
remoteFile: remoteBinLocation[_os] + binsToUpdate[i].name, |
|
|
|
localFile: rootLocation + localBinLocation[_os] + binsToUpdate[i].name, |
|
|
|
localFile: rootLocation + localBinLocation[_os] + 'patch/' + binsToUpdate[i].name, |
|
|
|
onProgress: function(received, total) { |
|
|
|
const percentage = (received * 100) / total; |
|
|
|
cache.io.emit('patch', { |
|
|
|
'msg': { |
|
|
|
'type': 'bins-update', |
|
|
|
'status': 'progress', |
|
|
|
'file': binsToUpdate[i].name, |
|
|
|
'bytesTotal': total, |
|
|
|
'bytesReceived': received |
|
|
|
} |
|
|
|
}); |
|
|
|
console.log(binsToUpdate[i].name + ' ' + percentage + '% | ' + received + ' bytes out of ' + total + ' bytes.'); |
|
|
|
} |
|
|
|
}) |
|
|
|
.then(function() { |
|
|
|
// verify that remote file is matching to DL'ed file
|
|
|
|
const localBinSize = fs.statSync(rootLocation + localBinLocation[_os] + binsToUpdate[i].name).size; |
|
|
|
const localBinSize = fs.statSync(rootLocation + localBinLocation[_os] + 'patch/' + binsToUpdate[i].name).size; |
|
|
|
console.log('compare dl file size'); |
|
|
|
|
|
|
|
|
|
|
|
if (localBinSize === binsToUpdate[i].rSize) { |
|
|
|
cache.io.emit('patch', { |
|
|
|
'msg': { |
|
|
|
'type': 'bins-update', |
|
|
|
'file': binsToUpdate[i].name, |
|
|
|
'status': 'done' |
|
|
|
} |
|
|
|
}); |
|
|
|
console.log('file ' + binsToUpdate[i].name + ' succesfully downloaded'); |
|
|
|
} else { |
|
|
|
cache.io.emit('patch', { |
|
|
|
'msg': { |
|
|
|
'type': 'bins-update', |
|
|
|
'file': binsToUpdate[i].name, |
|
|
|
'message': 'size mismatch' |
|
|
|
} |
|
|
|
}); |
|
|
|
console.log('error: ' + binsToUpdate[i].name + ' file size doesnt match remote!'); |
|
|
|
} |
|
|
|
}); |
|
|
@ -320,7 +360,7 @@ shepherd.get('/update-bins', function(req, res, next) { |
|
|
|
* type: |
|
|
|
* params: patchList |
|
|
|
*/ |
|
|
|
shepherd.get('/patch', function(req, res, next) { |
|
|
|
shepherd.get('/update/patch', function(req, res, next) { |
|
|
|
const successObj = { |
|
|
|
'msg': 'success', |
|
|
|
'result': 'dl started' |
|
|
@ -340,9 +380,10 @@ shepherd.updateAgama = function() { |
|
|
|
onProgress: function(received, total) { |
|
|
|
const percentage = (received * 100) / total; |
|
|
|
console.log('patch ' + percentage + '% | ' + received + ' bytes out of ' + total + ' bytes.'); |
|
|
|
cache.io.emit('service', { |
|
|
|
'patch': { |
|
|
|
'status': 'dl', |
|
|
|
cache.io.emit('patch', { |
|
|
|
'msg': { |
|
|
|
'status': 'progress', |
|
|
|
'type': 'ui', |
|
|
|
'progress': percentage, |
|
|
|
'bytesTotal': total, |
|
|
|
'bytesReceived': received |
|
|
@ -355,20 +396,29 @@ shepherd.updateAgama = function() { |
|
|
|
// verify that remote file is matching to DL'ed file
|
|
|
|
const localPatchSize = fs.statSync(rootLocation + 'patch.zip').size; |
|
|
|
console.log('compare dl file size'); |
|
|
|
|
|
|
|
|
|
|
|
if (localPatchSize === remotePatchSize) { |
|
|
|
console.log('patch succesfully downloaded'); |
|
|
|
console.log('extracting contents'); |
|
|
|
|
|
|
|
var zip = new AdmZip(rootLocation + 'patch.zip'); |
|
|
|
zip.extractAllTo(/*target path*/rootLocation + '/patch', /*overwrite*/true); |
|
|
|
const zip = new AdmZip(rootLocation + 'patch.zip'); |
|
|
|
zip.extractAllTo(/*target path*/rootLocation, /*overwrite*/true); |
|
|
|
// TODO: extract files in chunks
|
|
|
|
cache.io.emit('service', { |
|
|
|
'patch': { |
|
|
|
cache.io.emit('patch', { |
|
|
|
'msg': { |
|
|
|
'type': 'ui', |
|
|
|
'status': 'done' |
|
|
|
} |
|
|
|
}); |
|
|
|
fs.unlink(rootLocation + 'patch.zip'); |
|
|
|
} else { |
|
|
|
cache.io.emit('patch', { |
|
|
|
'msg': { |
|
|
|
'type': 'ui', |
|
|
|
'status': 'error', |
|
|
|
'message': 'size mismatch' |
|
|
|
} |
|
|
|
}); |
|
|
|
console.log('patch file size doesnt match remote!'); |
|
|
|
} |
|
|
|
}); |
|
|
@ -380,7 +430,7 @@ shepherd.updateAgama = function() { |
|
|
|
* type: |
|
|
|
* params: |
|
|
|
*/ |
|
|
|
shepherd.get('/update-check', function(req, res, next) { |
|
|
|
shepherd.get('/update/patch/check', function(req, res, next) { |
|
|
|
const rootLocation = path.join(__dirname, '../'); |
|
|
|
const options = { |
|
|
|
url: 'https://github.com/pbca26/dl-test/raw/master/version', |
|
|
@ -404,7 +454,11 @@ shepherd.get('/update-check', function(req, res, next) { |
|
|
|
} else { |
|
|
|
const successObj = { |
|
|
|
'msg': 'success', |
|
|
|
'result': 'update' |
|
|
|
'result': 'update', |
|
|
|
'version': { |
|
|
|
'local': localVersion[0], |
|
|
|
'remote': remoteVersion[0], |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
res.end(JSON.stringify(successObj)); |
|
|
|