Started work on file zip feature.
Ylian Saint-Hilaire committed
Aug 13, 2020 at 13:13 UTC
2d0f4010beb1600dfdf6b1e27269fa726d8b9d62
2 files changed
+36
-17
agents/meshcore.js
+19
-17
@@ -2138,6 +2138,19 @@ function createMeshCore(agent) {
2138
}
2139
break;
2140
}
2141
+ case 'zip':
2142
+ // Zip a bunch of files
2143
+ sendConsoleText('Zip: ' + JSON.stringify(cmd));
2144
+ var p = [];
2145
+ for (var i in cmd.files) { p.push(cmd.path + '/' + cmd.files[i]); }
2146
+ var ofile = cmd.path + '/' + cmd.outfile;
2147
+ sendConsoleText('Writing ' + ofile + '...');
2148
+ var out = require('fs').createWriteStream(ofile, { flags: 'wb' });
2149
+ out.fname = ofile;
2150
+ out.on('close', function () { sendConsoleText('DONE writing ' + this.fname); });
2151
+ var zip = require('zip-writer').write({ files: p });
2152
+ zip.pipe(out);
2153
+ break;
2154
default:
2155
// Unknown action, ignore it.
2156
break;
@@ -2518,12 +2531,9 @@ function createMeshCore(agent) {
2531
}
2532
break;
2533
case 'zip':
2521
- if (args['_'].length == 0)
2522
- {
2534
+ if (args['_'].length == 0) {
2535
response = "Proper usage: zip (output file name), input1 [, input n]"; // Display usage
2524
- }
2525
- else
2526
- {
2536
+ } else {
2537
var p = args['_'].join(' ').split(',');
2538
var ofile = p.shift();
2539
sendConsoleText('Writing ' + ofile + '...');
@@ -2536,24 +2546,16 @@ function createMeshCore(agent) {
2546
}
2547
break;
2548
case 'unzip':
2539
- if (args['_'].length == 0)
2540
- {
2549
+ if (args['_'].length == 0) {
2550
response = "Proper usage: unzip input, destination"; // Display usage
2542
- }
2543
- else
2544
- {
2551
+ } else {
2552
var p = args['_'].join(' ').split(',');
2546
- if (p.length != 2)
2547
- {
2548
- response = "Proper usage: unzip input, destination"; // Display usage
2549
- break;
2550
- }
2553
+ if (p.length != 2) { response = "Proper usage: unzip input, destination"; break; } // Display usage
2554
var prom = require('zip-reader').read(p[0]);
2555
prom._dest = p[1];
2556
prom.self = this;
2557
prom.sessionid = sessionid;
2555
- prom.then(function (zipped)
2556
- {
2558
+ prom.then(function (zipped) {
2559
sendConsoleText('Extracting to ' + this._dest + '...', this.sessionid);
2560
zipped.extractAll(this._dest).then(function () { sendConsoleText('finished unzipping', this.sessionid); }, function (e) { sendConsoleText('Error unzipping: ' + e, this.sessionid); }).parentPromise.sessionid = this.sessionid;
2561
}, function (e) { sendConsoleText('Error unzipping: ' + e, this.sessionid); });
views/default.handlebars
+17
@@ -730,6 +730,7 @@
730
<input type=button id=p13CutButton disabled="disabled" value="Cut" onclick="p13copyFile(1)" />
731
<input type=button id=p13CopyButton disabled="disabled" value="Copy" onclick="p13copyFile(0)" />
732
<input type=button id=p13PasteButton disabled="disabled" value="Paste" onclick="p13pasteFile()" />
733
+ <input type=button id=p13ZipButton disabled="disabled" value="Zip" onclick="p13zipFiles()" />
734
<input type=button id=p13RefreshButton disabled="disabled" value="Refresh" onclick="p13folderup(9999)" />
735
</div>
736
</td>
@@ -7839,6 +7840,7 @@
7840
QE('p13RefreshButton', false);
7841
QE('p13CutButton', false);
7842
QE('p13CopyButton', false);
7843
+ QE('p13ZipButton', false);
7844
QE('p13PasteButton', false);
7845
} else {
7846
var cc = p13getFileSelCount(), tc = p13getFileCount(), sfc = p13getFileSelCount(false); // In order: number of entires selected, number of total entries, number of selected entires that are files (not folders)
@@ -7853,6 +7855,7 @@
7855
QE('p13RefreshButton', true);
7856
QE('p13CutButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
7857
QE('p13CopyButton', (cc > 0) && (cc == sfc) && ((p13filetreelocation.length > 0) || (winAgent == false)));
7858
+ QE('p13ZipButton', (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false)));
7859
QE('p13PasteButton', ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0)));
7860
}
7861
}
@@ -7883,6 +7886,20 @@
7886
}
7887
}
7888
7889
+ function p13zipFiles() {
7890
+ var inputFiles = [], checkboxes = document.getElementsByName('fd');
7891
+ for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].checked) { inputFiles.push(p13filetree.dir[checkboxes[i].value].n); } }
7892
+ setDialogMode(2, "Zip Filename", 3, p13zipFilesEx, '<input type=text id=p13renameinput maxlength=64 onkeyup=p13fileNameCheck(event) style=width:100% value="" />', { action: 'zip', path: p13filetreelocation.join('/'), files: inputFiles});
7893
+ focusTextBox('p13renameinput');
7894
+ p13fileNameCheck();
7895
+ }
7896
+
7897
+ function p13zipFilesEx(b, tag) {
7898
+ tag.output = Q('p13renameinput').value;
7899
+ if (!tag.output.toLowerCase().endsWith('.zip')) { tag.output += '.zip'; }
7900
+ files.sendText(tag);
7901
+ }
7902
+
7903
var p13clipboard = null, p13clipboardFolder = null, p13clipboardCut = 0;
7904
function p13copyFile(cut) { var checkboxes = document.getElementsByName('fd'); p13clipboard = []; p13clipboardCut = cut, p13clipboardFolder = p13targetpath; for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && (checkboxes[i].attributes.file.value == '3')) { p13clipboard.push(p13filetree.dir[checkboxes[i].value].n); } } p13updateClipview(); }
7905
function p13pasteFile() {