Fixed a bug in the server handler app.js

This commit is contained in:
2023-07-27 18:37:25 +02:00
parent 57a4359e19
commit ae7914b9eb

View File

@ -1,5 +1,6 @@
const {Client} = require("ssh2"); const {Client} = require("ssh2");
const fs = require("fs"); const fs = require("fs");
const {getReleaseInformation} = require("../controller/shell");
const services = fs.readdirSync(__dirname + "/apps").map((item) => item.replace(".js", "")); const services = fs.readdirSync(__dirname + "/apps").map((item) => item.replace(".js", ""));
module.exports = (io, socket) => { module.exports = (io, socket) => {
@ -40,11 +41,11 @@ module.exports = (io, socket) => {
socket.emit("install", {status: "success", step}); socket.emit("install", {status: "success", step});
queue.shift(); queue.shift();
execQueue(); execQueue();
}).on("data", () => {}); }).on("data", (e) => {console.log(e.toString())});
}); });
} }
socket.on("install", (msg) => { socket.on("install", async (msg) => {
if (!connected) return socket.emit("install", {status: "failed", message: "Not connected"}); if (!connected) return socket.emit("install", {status: "failed", message: "Not connected"});
if (queue.length > 0) return socket.emit("install", {status: "failed", message: "Another installation is in progress"}); if (queue.length > 0) return socket.emit("install", {status: "failed", message: "Another installation is in progress"});
@ -56,6 +57,8 @@ module.exports = (io, socket) => {
let infoData = []; let infoData = [];
const os = (await getReleaseInformation(session, false).catch(() => {}))?.id?.toLowerCase();
app.steps.map((mappedItem, index) => { app.steps.map((mappedItem, index) => {
let item = {...mappedItem}; let item = {...mappedItem};
Object.keys(app.variables).map((key) => { Object.keys(app.variables).map((key) => {
@ -67,16 +70,18 @@ module.exports = (io, socket) => {
if (msg?.data[key] !== value) return; if (msg?.data[key] !== value) return;
} }
if (item.os && item.os !== os) return;
if (item.replace) { if (item.replace) {
Object.keys(item.replace).map((key) => { Object.keys(item.replace).map((key) => {
item.command = item.command.replace(new RegExp(`{${key}}`, "g"), item.replace[key]()); item.command = item.command.replace(new RegExp(`{${key}}`, "g"), item.replace[key]());
}); });
} }
queue.push({...item, step: index+1}); queue.push({...item, step: index + 1});
if (item.description) if (item.description)
infoData.push({description: item.description, step: index+1}); infoData.push({description: item.description, step: index + 1});
}); });
socket.emit("install", {status: "info", data: infoData}); socket.emit("install", {status: "info", data: infoData});