mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-23 14:46:49 +03:00
First working zip feature in device files tab.
This commit is contained in:
parent
209778fe7c
commit
027876d169
@ -2140,17 +2140,34 @@ function createMeshCore(agent) {
|
||||
}
|
||||
case 'zip':
|
||||
// Zip a bunch of files
|
||||
sendConsoleText('Zip: ' + JSON.stringify(cmd));
|
||||
var p = [];
|
||||
for (var i in cmd.files) { p.push(cmd.path + '/' + cmd.files[i]); }
|
||||
var ofile = cmd.path + '/' + cmd.outfile;
|
||||
sendConsoleText('Writing ' + ofile + '...');
|
||||
var fp, stat, p = [];
|
||||
for (var i in cmd.files) {
|
||||
// Right now, we only zip files.
|
||||
// TODO: Support folder compression
|
||||
// TODO: Support compression relative to a root path
|
||||
// TODO: Support the 'cancel' operation below
|
||||
fp = cmd.path + '/' + cmd.files[i];
|
||||
stat = null;
|
||||
try { stat = fs.statSync(fp); } catch (e) { }
|
||||
if ((stat != null) && (stat.isDirectory() == false) && (stat.size != null) && (stat.size > 0)) { p.push(fp); }
|
||||
}
|
||||
if (p.length == 0) return;
|
||||
var ofile = cmd.path + '/' + cmd.output;
|
||||
this.write(Buffer.from(JSON.stringify({ action: 'dialogmessage', msg: 'zipping' })));
|
||||
var out = require('fs').createWriteStream(ofile, { flags: 'wb' });
|
||||
out.fname = ofile;
|
||||
out.on('close', function () { sendConsoleText('DONE writing ' + this.fname); });
|
||||
out.xws = this;
|
||||
out.on('close', function () {
|
||||
this.xws.write(Buffer.from(JSON.stringify({ action: 'dialogmessage', msg: null })));
|
||||
this.xws.write(Buffer.from(JSON.stringify({ action: 'refresh' })));
|
||||
});
|
||||
var zip = require('zip-writer').write({ files: p });
|
||||
zip.pipe(out);
|
||||
break;
|
||||
case 'cancel':
|
||||
// TODO: Cancel zip operation if present
|
||||
//sendConsoleText('Cancel operation');
|
||||
break;
|
||||
default:
|
||||
// Unknown action, ignore it.
|
||||
break;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7651,6 +7651,7 @@
|
||||
QV('filesRecordIcon', false);
|
||||
p13setActions();
|
||||
if (files != null) { files.Stop(); files = null; }
|
||||
if (xxdialogTag == 'fileMsgDialog') { setDialogMode(0); }
|
||||
break;
|
||||
case 3:
|
||||
p13targetpath = '';
|
||||
@ -7709,6 +7710,8 @@
|
||||
var p13targetpath = null;
|
||||
var p13filetreelocation = [];
|
||||
|
||||
function p13fileOperationDialogEx(b) { if ((b == 0) && (files != null)) { files.sendText({ action: 'cancel' }); } }
|
||||
|
||||
function p13gotFiles(data) {
|
||||
if ((data.length > 0) && (data.charCodeAt(0) != 123)) { p13gotDownloadBinaryData(data); return; } // This is ok because 4 first bytes is a control value.
|
||||
//console.log('p13gotFiles', data);
|
||||
@ -7718,6 +7721,20 @@
|
||||
// Process file upload commands
|
||||
if ((data.action != null) && (data.action.startsWith('upload'))) { p13gotUploadData(data); return; }
|
||||
|
||||
// Display a dialog message
|
||||
if (data.action == 'dialogmessage') {
|
||||
if ((data.msg == null) && (xxdialogTag == 'fileMsgDialog')) {
|
||||
setDialogMode(0); // Close the dialog box
|
||||
} else if ((data.msg == 'zipping') && ((!xxdialogMode) || (xxdialogTag == 'fileMsgDialog'))) {
|
||||
// Show the dialog box message
|
||||
setDialogMode(2, "File Operation", 10, p13fileOperationDialogEx, '<div style=margin:10px>' + "Compressing files..." + '<div>', 'fileMsgDialog');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Refresh file folder
|
||||
if (data.action == 'refresh') { p13folderup(9999); return; }
|
||||
|
||||
if (data.path != null) {
|
||||
data.path = data.path.replace(/\//g, '\\');
|
||||
if ((p13filetree != null) && (data.path == p13filetree.path)) {
|
||||
|
Loading…
Reference in New Issue
Block a user