pare down some changes
This commit is contained in:
+1
-8
@@ -25,17 +25,10 @@ app.get('/js/*.js', function(req, res){
|
|||||||
res.sendFile(__dirname + req.url);
|
res.sendFile(__dirname + req.url);
|
||||||
});
|
});
|
||||||
|
|
||||||
const SHELL_ARGS = {
|
|
||||||
bash: ['--login'],
|
|
||||||
'cmd.exe': [],
|
|
||||||
};
|
|
||||||
|
|
||||||
var shell_name = process.platform === 'win32' ? 'cmd.exe' : 'bash';
|
|
||||||
|
|
||||||
app.post('/terminals', function (req, res) {
|
app.post('/terminals', function (req, res) {
|
||||||
var cols = parseInt(req.query.cols),
|
var cols = parseInt(req.query.cols),
|
||||||
rows = parseInt(req.query.rows),
|
rows = parseInt(req.query.rows),
|
||||||
term = pty.spawn(shell_name, SHELL_ARGS[shell_name], {
|
term = pty.spawn(process.platform === 'win32' ? 'cmd.exe' : 'bash', [], {
|
||||||
encoding: null,
|
encoding: null,
|
||||||
name: 'xterm-color',
|
name: 'xterm-color',
|
||||||
cols: cols || 80,
|
cols: cols || 80,
|
||||||
|
|||||||
@@ -23,43 +23,6 @@
|
|||||||
<div id="terminal-container"></div>
|
<div id="terminal-container"></div>
|
||||||
|
|
||||||
<div id="zmodem_controls">
|
<div id="zmodem_controls">
|
||||||
<form id="zm_start" style="display: none" action="javascript:void(0)">
|
|
||||||
ZMODEM detected: Start ZMODEM session?
|
|
||||||
<label><input id="zmstart_yes" name="zmstart" type=radio checked value="1"> Yes</label>
|
|
||||||
|
|
||||||
<label><input name="zmstart" type=radio value=""> No</label>
|
|
||||||
<button type="submit">Submit</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="zm_offer" style="display: none" action="javascript:void(0)">
|
|
||||||
<p>ZMODEM File offered!</p>
|
|
||||||
|
|
||||||
<label><input id="zmaccept_yes" name="zmaccept" type=radio checked value="1"> Accept</label>
|
|
||||||
|
|
||||||
<label><input name="zmaccept" type=radio value=""> Skip</label>
|
|
||||||
<button type="submit">Submit</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div id="zm_file" style="display: none">
|
|
||||||
<div>Name: <span id="name"></span></div>
|
|
||||||
<div>Size: <span id="size"></span></div>
|
|
||||||
<div>Last modified: <span id="mtime"></span></div>
|
|
||||||
<div>Mode: <span id="mode"></span></div>
|
|
||||||
<br>
|
|
||||||
<div>Conversion: <span id="zfile_conversion"></span></div>
|
|
||||||
<div>Management: <span id="zfile_management"></span></div>
|
|
||||||
<div>Transport: <span id="zfile_transport"></span></div>
|
|
||||||
<div>Sparse? <span id="zfile_sparse"></span></div>
|
|
||||||
<br>
|
|
||||||
<div>Files remaining in batch: <span id="files_remaining"></span></div>
|
|
||||||
<div>Bytes remaining in batch: <span id="bytes_remaining"></span></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form id="zm_progress" style="display: none" action="javascript:void(0)">
|
|
||||||
<div><span id="percent_received"></span>% (<span id="bytes_received"></span> bytes) received</div>
|
|
||||||
<button id="zm_progress_skipper" type="button" onclick="skip_current_file();">Skip File</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="zm_choose" style="display: none" action="javascript:void(0)">
|
<form id="zm_choose" style="display: none" action="javascript:void(0)">
|
||||||
<label>Choose file(s): <input id="zm_files" type="file" multiple></label>
|
<label>Choose file(s): <input id="zm_files" type="file" multiple></label>
|
||||||
<button type="submit">Send</button>
|
<button type="submit">Send</button>
|
||||||
|
|||||||
+23
-178
@@ -114,165 +114,40 @@ function createTerminal() {
|
|||||||
|
|
||||||
term.zmodemAttach(socket);
|
term.zmodemAttach(socket);
|
||||||
|
|
||||||
term.on("zmodemRetract", () => {
|
|
||||||
start_form.style.display = "none";
|
|
||||||
start_form.onsubmit = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
term.on("zmodemDetect", (detection) => {
|
term.on("zmodemDetect", (detection) => {
|
||||||
function do_zmodem() {
|
term.detach();
|
||||||
term.detach();
|
let zsession = detection.confirm();
|
||||||
let zsession = detection.confirm();
|
|
||||||
|
|
||||||
var promise;
|
var promise;
|
||||||
|
|
||||||
if (zsession.type === "receive") {
|
if (zsession.type === "receive") {
|
||||||
promise = _handle_receive_session(zsession);
|
promise = zmodemHandleReceiveSession(zsession);
|
||||||
}
|
|
||||||
else {
|
|
||||||
promise = _handle_send_session(zsession);
|
|
||||||
}
|
|
||||||
|
|
||||||
promise.catch( console.error.bind(console) ).then( () => {
|
|
||||||
term.attach(socket);
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_auto_zmodem()) {
|
|
||||||
do_zmodem();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
start_form.style.display = "";
|
promise = zmodemHandleSendSession(zsession);
|
||||||
start_form.onsubmit = function(e) {
|
|
||||||
start_form.style.display = "none";
|
|
||||||
|
|
||||||
if (document.getElementById("zmstart_yes").checked) {
|
|
||||||
do_zmodem();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
detection.deny();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
promise.catch( console.error.bind(console) ).then( () => {
|
||||||
|
term.attach(socket);
|
||||||
|
} );
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
function zmodemHandleReceiveSession(zsession) {
|
||||||
// UI STUFF
|
|
||||||
|
|
||||||
function _show_file_info(xfer) {
|
|
||||||
var file_info = xfer.get_details();
|
|
||||||
|
|
||||||
document.getElementById("name").textContent = file_info.name;
|
|
||||||
document.getElementById("size").textContent = file_info.size;
|
|
||||||
document.getElementById("mtime").textContent = file_info.mtime;
|
|
||||||
document.getElementById("files_remaining").textContent = file_info.files_remaining;
|
|
||||||
document.getElementById("bytes_remaining").textContent = file_info.bytes_remaining;
|
|
||||||
|
|
||||||
document.getElementById("mode").textContent = "0" + file_info.mode.toString(8);
|
|
||||||
|
|
||||||
var xfer_opts = xfer.get_options();
|
|
||||||
["conversion", "management", "transport", "sparse"].forEach( (lbl) => {
|
|
||||||
document.getElementById(`zfile_${lbl}`).textContent = xfer_opts[lbl];
|
|
||||||
} );
|
|
||||||
|
|
||||||
document.getElementById("zm_file").style.display = "";
|
|
||||||
}
|
|
||||||
function _hide_file_info() {
|
|
||||||
document.getElementById("zm_file").style.display = "none";
|
|
||||||
}
|
|
||||||
|
|
||||||
function _save_to_disk(xfer, buffer) {
|
|
||||||
return Zmodem.Browser.save_to_disk(buffer, xfer.get_details().name);
|
|
||||||
}
|
|
||||||
|
|
||||||
var skipper_button = document.getElementById("zm_progress_skipper");
|
|
||||||
var skipper_button_orig_text = skipper_button.textContent;
|
|
||||||
|
|
||||||
function _show_progress() {
|
|
||||||
skipper_button.disabled = false;
|
|
||||||
skipper_button.textContent = skipper_button_orig_text;
|
|
||||||
|
|
||||||
document.getElementById("bytes_received").textContent = 0;
|
|
||||||
document.getElementById("percent_received").textContent = 0;
|
|
||||||
|
|
||||||
document.getElementById("zm_progress").style.display = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function _update_progress(xfer) {
|
|
||||||
var total_in = xfer.get_offset();
|
|
||||||
|
|
||||||
document.getElementById("bytes_received").textContent = total_in;
|
|
||||||
|
|
||||||
var percent_received = 100 * total_in / xfer.get_details().size;
|
|
||||||
document.getElementById("percent_received").textContent = percent_received.toFixed(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function _hide_progress() {
|
|
||||||
document.getElementById("zm_progress").style.display = "none";
|
|
||||||
}
|
|
||||||
|
|
||||||
var start_form = document.getElementById("zm_start");
|
|
||||||
|
|
||||||
function _auto_zmodem() {
|
|
||||||
return document.getElementById("zmodem-auto").checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
// END UI STUFF
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
|
|
||||||
function _handle_receive_session(zsession) {
|
|
||||||
zsession.on("offer", function(xfer) {
|
zsession.on("offer", function(xfer) {
|
||||||
current_receive_xfer = xfer;
|
xfer.accept().then(
|
||||||
|
(inputs) => {
|
||||||
_show_file_info(xfer);
|
Zmodem.Browser.save_to_disk(inputs, xfer.get_details().name);
|
||||||
|
},
|
||||||
var offer_form = document.getElementById("zm_offer");
|
console.error.bind(console)
|
||||||
|
);
|
||||||
function on_form_submit() {
|
|
||||||
offer_form.style.display = "none";
|
|
||||||
|
|
||||||
//START
|
|
||||||
//if (offer_form.zmaccept.value) {
|
|
||||||
if (_auto_zmodem() || document.getElementById("zmaccept_yes").checked) {
|
|
||||||
_show_progress();
|
|
||||||
|
|
||||||
var FILE_BUFFER = [];
|
|
||||||
xfer.on("input", (payload) => {
|
|
||||||
_update_progress(xfer);
|
|
||||||
FILE_BUFFER.push( new Uint8Array(payload) );
|
|
||||||
});
|
|
||||||
xfer.accept().then(
|
|
||||||
() => {
|
|
||||||
_save_to_disk(xfer, FILE_BUFFER);
|
|
||||||
},
|
|
||||||
console.error.bind(console)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
xfer.skip();
|
|
||||||
}
|
|
||||||
//END
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_auto_zmodem()) {
|
|
||||||
on_form_submit();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
offer_form.onsubmit = on_form_submit;
|
|
||||||
offer_form.style.display = "";
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
var promise = new Promise( (res) => {
|
var promise = new Promise( (res) => {
|
||||||
zsession.on("session_end", () => {
|
zsession.on("session_end", res);
|
||||||
_hide_file_info();
|
|
||||||
_hide_progress();
|
|
||||||
res();
|
|
||||||
} );
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
zsession.start();
|
zsession.start();
|
||||||
@@ -280,11 +155,11 @@ function _handle_receive_session(zsession) {
|
|||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _handle_send_session(zsession) {
|
function zmodemHandleSendSession(zsession) {
|
||||||
var choose_form = document.getElementById("zm_choose");
|
var choose_form = document.getElementById("zm_choose");
|
||||||
choose_form.style.display = "";
|
choose_form.style.display = "";
|
||||||
|
|
||||||
var promise = new Promise( (res) => {
|
return new Promise( (res) => {
|
||||||
choose_form.onsubmit = function(e) {
|
choose_form.onsubmit = function(e) {
|
||||||
choose_form.style.display = "none";
|
choose_form.style.display = "none";
|
||||||
|
|
||||||
@@ -293,43 +168,13 @@ function _handle_send_session(zsession) {
|
|||||||
|
|
||||||
Zmodem.Browser.send_files(
|
Zmodem.Browser.send_files(
|
||||||
zsession,
|
zsession,
|
||||||
files_obj,
|
files_obj
|
||||||
{
|
).then(
|
||||||
on_offer_response(obj, xfer) {
|
|
||||||
if (xfer) _show_progress();
|
|
||||||
//console.log("offer", xfer ? "accepted" : "skipped");
|
|
||||||
},
|
|
||||||
on_progress(obj, xfer) {
|
|
||||||
_update_progress(xfer);
|
|
||||||
},
|
|
||||||
on_file_complete(obj) {
|
|
||||||
//console.log("COMPLETE", obj);
|
|
||||||
_hide_progress();
|
|
||||||
},
|
|
||||||
}
|
|
||||||
).then(_hide_progress).then(
|
|
||||||
zsession.close.bind(zsession),
|
zsession.close.bind(zsession),
|
||||||
console.error.bind(console)
|
console.error.bind(console)
|
||||||
).then( () => {
|
).then(res);
|
||||||
_hide_file_info();
|
|
||||||
_hide_progress();
|
|
||||||
res();
|
|
||||||
} );
|
|
||||||
};
|
};
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
//This is here to allow canceling of an in-progress ZMODEM transfer.
|
|
||||||
var current_receive_xfer;
|
|
||||||
|
|
||||||
//Called from HTML directly.
|
|
||||||
function skip_current_file() {
|
|
||||||
current_receive_xfer.skip();
|
|
||||||
|
|
||||||
skipper_button.disabled = true;
|
|
||||||
skipper_button.textContent = "Waiting for server to acknowledge skip …";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function runRealTerminal() {
|
function runRealTerminal() {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* See zmodem.js’s documentation for more details.
|
* See zmodem.js’s documentation for more details.
|
||||||
*
|
*
|
||||||
* **IMPORTANT:** After you confirm() a zmodem.js Detection, if you have
|
* **IMPORTANT:** After you confirm() a zmodem.js Detection, if you have
|
||||||
* used the `attach` or `turbinado` addons, you’ll need to suspend their
|
* used the `attach` or `terminado` addons, you’ll need to suspend their
|
||||||
* operation for the duration of the ZMODEM session. (The demo does this
|
* operation for the duration of the ZMODEM session. (The demo does this
|
||||||
* via `detach()` and a re-`attach()`.)
|
* via `detach()` and a re-`attach()`.)
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user