mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 15:04:52 +09:00
Added fetch mod meta functionality
Fixed bug in settings with new UI Re-added mod nav options
This commit is contained in:
1 parent
1788d72f8f
commit
dc9d8bf987
5 files changed
+80
-21
No files matched your search
@@ -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)
|
||||
|
||||
@@ -11,6 +11,26 @@
|
||||
<div class="nav-item mr-1">
|
||||
<a class="nav-link align-middle" href="/nodes">Slaves</a>
|
||||
</div>
|
||||
<%# 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 %>
|
||||
<div class="nav-item">
|
||||
<a class="nav-link align-middle" href="/settings">Settings</a>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
<%- include("nav.html") %>
|
||||
<div id="body" class="container">
|
||||
<div id="hero">
|
||||
<h2>Slave details</h2>
|
||||
<div id="display">
|
||||
|
||||
</div>
|
||||
|
||||
+29
-17
@@ -113,17 +113,24 @@ function populateSlaveInfo(){
|
||||
let HTML = '<div class="jumbotron mt-5"><div id="header">' +
|
||||
'<h1 class="display-4"><i id="online-indicator" class="mr-3 fas"></i> ' + slave.instanceName+"</h1>";
|
||||
HTML += '<div class="stats" id="node-stats">' +
|
||||
'<nav aria-label="breadcrumb">\n' +
|
||||
' <ol class="breadcrumb"><li class="breadcrumb-item">Host: '+slave.mac+'</li>' +
|
||||
'<nav class="mt-3" aria-label="breadcrumb">\n' +
|
||||
' <ol class="breadcrumb align-content-center"><li class="breadcrumb-item">Host: '+slave.mac+'</li>' +
|
||||
'<li class="breadcrumb-item">Unique: '+slave.unique+'</li>';
|
||||
if(slave.publicIP !== "localhost"){
|
||||
HTML += '<li class="breadcrumb-item">IP: '+slave.publicIP+':'+slave.serverPort+'</li>';
|
||||
} else {
|
||||
HTML += '<li class="breadcrumb-item">This server is not configured for incoming connections</li>';
|
||||
}
|
||||
if(slave.meta)
|
||||
for(let key in slave.meta){
|
||||
let t = slave.meta[key];
|
||||
if(typeof t == "string"){
|
||||
HTML += "<li class=\"breadcrumb-item\">"+key+": "+t+"</li>";
|
||||
}
|
||||
}
|
||||
HTML += '<li class="breadcrumb-item">Last seen: <span id="lastSeenDate">'+moment(Number(slave.time)).fromNow()+"</span></li>";
|
||||
HTML += '<li class="breadcrumb-item">Online players: '+slave.playerCount+"</li></ol></nav>";
|
||||
|
||||
|
||||
// detect if remoteMap mod is installed, if it is we want to show the link for it
|
||||
let hasRemoteMap = false;
|
||||
slave.mods.forEach(mod => {
|
||||
@@ -139,13 +146,13 @@ function populateSlaveInfo(){
|
||||
HTML += "</div>"; // end of displayBody
|
||||
|
||||
// list mods and other metadata
|
||||
HTML += '<h2 class="subtitle d-inline">Mods</h2><a class="btn btn-primary float-right m-2">Fetch Mod Data</a>' +
|
||||
HTML += '<h2 class="subtitle d-inline">Mods</h2><a id="fetch-mod-data" class="btn btn-primary float-right m-2">Fetch Mod Data</a>' +
|
||||
'<table id="modlist" class="table table-striped table-hover">' +
|
||||
' <thead>\n' +
|
||||
' <tr>\n' +
|
||||
' <th scope="col">#</th>\n' +
|
||||
' <th scope="col">Version</th>\n' +
|
||||
' <th scope="col">Filename</th>\n' +
|
||||
' <th scope="col">Name</th>\n' +
|
||||
' <th scope="col">Summary</th>\n' +
|
||||
' </tr>\n' +
|
||||
' </thead>' +
|
||||
@@ -167,18 +174,8 @@ function populateSlaveInfo(){
|
||||
HTML += '<div id="' + slave.unique + '" class="productionGraph" style="width: calc(100% - 300px);"></div>';
|
||||
// terminal
|
||||
// HTML += '<div id="terminal"></div>';
|
||||
|
||||
document.querySelector("#hero").innerHTML = HTML;
|
||||
|
||||
// slaveDetails
|
||||
HTML = "";
|
||||
if(slave.meta)
|
||||
for(let key in slave.meta){
|
||||
let t = slave.meta[key];
|
||||
if(typeof t == "string"){
|
||||
HTML += "<p>"+key+": "+t+"</p>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
document.querySelector("#body > #details").innerHTML = HTML;
|
||||
|
||||
@@ -186,8 +183,23 @@ function populateSlaveInfo(){
|
||||
makeGraph(slave.unique, slave.unique)
|
||||
|
||||
// makeTerminal();
|
||||
|
||||
$('#fetch-mod-data').on("click", downloadSaveModData);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function downloadSaveModData() {
|
||||
let modRows = $("#modlist tbody tr");
|
||||
for (let i = 0; i < modRows.length; i++) {
|
||||
let modName = modRows[i].children[2].innerText;
|
||||
$.getJSON( "/api/modmeta?modname=" + modName, function( data ) {
|
||||
modRows[i].children[2].innerHTML = data.title;
|
||||
modRows[i].children[3].innerHTML = data.summary
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var slaveLogin = {};
|
||||
function makeTerminal(){
|
||||
myTerminal = new Terminal();
|
||||
|
||||
+3
-3
@@ -16,10 +16,10 @@ window.onload = function(){
|
||||
for(let i = 0; i < sliders.length; i++) {
|
||||
sliders[i].onclick = function() {
|
||||
let settings = JSON.parse(localStorage.settings);
|
||||
|
||||
let selectedSliderParent = $(this.parentElement.parentElement);
|
||||
// walk through DOM structure created by drawSetting and update localstorage from that
|
||||
console.log(this.parentElement.parentElement.childNodes[0].innerHTML + " = " + !this.parentElement.childNodes[0].checked);
|
||||
settings[this.parentElement.parentElement.childNodes[0].innerHTML] = !this.parentElement.childNodes[0].checked;
|
||||
console.log(selectedSliderParent.find('.settings-text').html() + " = " + (selectedSliderParent.find("label input").val() === 'on'));
|
||||
settings[selectedSliderParent.find('.settings-text').html()] = (selectedSliderParent.find("label input").val() === 'on');
|
||||
|
||||
localStorage.settings = JSON.stringify(settings);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user