diff --git a/master.js b/master.js index c19d45de..c030f57c 100644 --- a/master.js +++ b/master.js @@ -44,6 +44,7 @@ const bcrypt = require('bcryptjs'); const crypto = require('crypto'); const base64url = require('base64url'); const moment = require("moment"); +const request = require("request") // constants console.log(`Requiring config from ${args.config || './config'}`) @@ -644,6 +645,33 @@ app.get("/api/inventoryAsObject", function(req, res) { res.send(JSON.stringify(db.items)); }); +/** + GET endpoint to read the masters inventory as an object with key:value pairs + + @memberof clusterioMaster + @instance + @alias api/modData + @returns {object} JSON + */ + +// wrap a request in an promise + async function downloadPage(url) { + return new Promise((resolve, reject) => { + request(url, (error, response, body) => { + resolve(body); + }); + }); + } + +app.get("/api/modmeta", async function(req, res) { + endpointHitCounter.labels(req.route.path).inc(); + res.header("Access-Control-Allow-Origin", "*"); + res.setHeader('Content-Type', 'application/json'); + let modData = await downloadPage("https://mods.factorio.com/api/mods/" + req.query.modname); + res.send(modData); +}); + + /** POST endpoint for running commands on slaves. Requires x-access-token header to be set. Find you api token in secret-api-token.txt on the master (after running it once) diff --git a/static/nav.html b/static/nav.html index 537068d6..44f90a62 100644 --- a/static/nav.html +++ b/static/nav.html @@ -11,6 +11,26 @@ + <%# Very ugly ejs code to hide the Players button if the playerManager plugin isn`t installed %> + <% + sidebarPluginButtonsHtml = ""; + for(let o in masterPlugins){ + let plug = masterPlugins[o]; + if(plug.main + && plug.main.ui + && typeof plug.main.ui.sidebar == "object" + && Array.isArray(plug.main.ui.sidebar)){ + let sidebarEntries = plug.main.ui.sidebar; + for(let i in sidebarEntries){ + let button = sidebarEntries[i]; + if(button.getHtml && typeof button.getHtml == "function"){ + sidebarPluginButtonsHtml += button.getHtml(); + } + } + } + } + %> + <%- sidebarPluginButtonsHtml %> diff --git a/static/nodeDetails.html b/static/nodeDetails.html index 9865e441..4851b9e3 100644 --- a/static/nodeDetails.html +++ b/static/nodeDetails.html @@ -10,7 +10,6 @@ <%- include("nav.html") %>
-

Slave details

diff --git a/static/nodeDetails.js b/static/nodeDetails.js index 3334b562..e95585c6 100644 --- a/static/nodeDetails.js +++ b/static/nodeDetails.js @@ -113,17 +113,24 @@ function populateSlaveInfo(){ let HTML = '