Browse Source

updater (ui)

all-modes
pbca26 8 years ago
parent
commit
2ef5bd2b47
  1. 1
      package.json
  2. 86
      routes/shepherd.js

1
package.json

@ -33,6 +33,7 @@
"graceful-fs": "^4.1.11", "graceful-fs": "^4.1.11",
"md5": "^2.2.1", "md5": "^2.2.1",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"nodejs-aes256": "^1.0.1",
"pm2": "^2.4.3", "pm2": "^2.4.3",
"portscanner": "^2.1.1", "portscanner": "^2.1.1",
"ps-node": "^0.1.5", "ps-node": "^0.1.5",

86
routes/shepherd.js

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

Loading…
Cancel
Save