From c1efc80017ec5f3d6e492749cb19c947c57fd7c0 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Thu, 28 Feb 2019 00:26:16 +0000 Subject: [webapp/ipxe] Add scroll to bottom feature, fix multiline bug and fix cancel --- server/lib/shell.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'server/lib/shell.js') diff --git a/server/lib/shell.js b/server/lib/shell.js index 81d3008..fd5151f 100644 --- a/server/lib/shell.js +++ b/server/lib/shell.js @@ -31,41 +31,59 @@ module.exports = { // Cloning git. sendToLog(ipxeVersion, 'Cloning git ...\n', 'primary') await cloneIpxe(ipxeVersion) + if (!building[ipxeVersion]) return // Copying configs. sendToLog(ipxeVersion, 'Copying configs ...\n', 'primary') copyConfigs(ipxeVersion) + if (!building[ipxeVersion]) return // Make ipxe. sendToLog(ipxeVersion, 'Make iPXE ...\n', 'primary') shell.cd(path.join(__appdir, 'ipxe', 'ipxe_' + ipxeVersion, 'src')) await new Promise((resolve, reject) => { + if (!building[ipxeVersion]) return make[ipxeVersion] = shell.exec(makeCmd, { async: true }, () => { // make[ipxeVersion] = child.exec(makeCmd, { async: true }, () => { - updateInProgress(ipxeVersion, false) resolve() }) // Send the output to the frontend log. make[ipxeVersion].stdout.on('data', data => { - sendToLog(ipxeVersion, data, 'normal') + const multiline = data.split('\n') + if (multiline.length > 2) { + multiline.forEach(line => { + if (line) sendToLog(ipxeVersion, line, 'normal') + }) + } else sendToLog(ipxeVersion, data, 'normal') }) make[ipxeVersion].stderr.on('data', data => { - sendToLog(ipxeVersion, data, 'error') + const multiline = data.split('\n') + if (multiline.length > 2) { + multiline.forEach(line => { + if (line) sendToLog(ipxeVersion, line, 'error') + }) + } else sendToLog(ipxeVersion, data, 'error') }) }) + if (!building[ipxeVersion]) return // Copy and rename the ipxe file. + sendToLog(ipxeVersion, 'Copying ipxe file ...\n', 'primary') shell.cp('bin/undionly.kpxe', path.join(__appdir, 'ipxe')) shell.mv(path.join(__appdir, 'ipxe', 'undionly.kpxe'), path.join(__appdir, 'ipxe', 'ipxe.' + ipxeVersion)) + sendToLog(ipxeVersion, 'done\n', 'success') + updateInProgress(ipxeVersion, false) }, cancelBuilding: async function (req, res) { - const process = make[req.params.version] + const ipxeVersion = req.params.version + const process = make[ipxeVersion] if (process) { const kill = 'pkill -P ' + process.pid shell.exec(kill) + updateInProgress(ipxeVersion, false) } res.send({ status: 'SUCCESS', data: process }) }, -- cgit v1.2.3-55-g7522