luci-mod-network: diagnostics: add realtime command output

The diagnostics page is using `fs.exec()` to execute command, which blocks
until command exit. Users have to wait for a while to see the result.

When doing IPv6 traceroute, this may cause XHR timeout, if target host
is unreachable. (See issue #7210)

This commit uses new `responseProgress` callback and `stderr` option
added in luci.js and fs.js to update command output.

Signed-off-by: Richard Yu <yurichard3839@gmail.com>
Link: https://github.com/openwrt/luci/pull/7920
This commit is contained in:
Richard Yu
2025-09-01 22:43:16 +08:00
committed by Paul Donald
parent ece28ab5a4
commit 122a5ba73e

View File

@@ -8,15 +8,16 @@
return view.extend({ return view.extend({
handleCommand: function(exec, args) { handleCommand: function(exec, args) {
var buttons = document.querySelectorAll('.diag-action > .cbi-button'); var buttons = document.querySelectorAll('.diag-action > .cbi-button'),
out = document.querySelector('textarea');
for (var i = 0; i < buttons.length; i++) for (var i = 0; i < buttons.length; i++)
buttons[i].setAttribute('disabled', 'true'); buttons[i].setAttribute('disabled', 'true');
return fs.exec(exec, args).then(function(res) { return fs.exec_direct(exec, args, 'text', false, true, function(ev) {
var out = document.querySelector('textarea'); out.textContent = ev.target.response;
}).then(function(res) {
dom.content(out, [ res.stdout || '', res.stderr || '' ]); out.textContent = res;
}).catch(function(err) { }).catch(function(err) {
ui.addNotification(null, E('p', [ err ])) ui.addNotification(null, E('p', [ err ]))
}).finally(function() { }).finally(function() {