Very big changes to help custom config paths

This commit is contained in:
Daniel Vestøl committed 2018-07-13 22:56:10 +02:00
1 parent 02c545c650
commit 98131ee66e
5 files changed
+59 -44

No files matched your search

+3
View File
@@ -454,6 +454,9 @@ write-data=${ path.resolve(config.instanceDirectory, instance) }\r\n
confirmedOrders = [];
lastSignalCheck = Date.now();
});
} else {
console.error("Invalid arguments, quitting.");
process.exit(1);
}
// ensure instancemanagement only ever runs once
+7 -5
View File
@@ -1,8 +1,10 @@
const jwt = require('jsonwebtoken');
const config = require("./../config");
// const config = require("./../config");
var middleware = function (req, res, next) {
module.exports = function(config){
return {
middleware: function (req, res, next) {
var token = req.headers['x-access-token'];
if(!token) return res.status(401).send({ auth: false, message: 'No token provided.', endpoint: req.route.path});
@@ -10,6 +12,6 @@ var middleware = function (req, res, next) {
if(err) return res.status(500).send({ auth: false, message: 'Failed to authenticate token.', endpoint: req.route.path});
next();
});
}
module.exports = {middleware};
},
}
};
+4 -2
View File
@@ -1,7 +1,8 @@
const fileOps = require("_app/fileOps");
const config = require("./../config");
// const config = require("./../config");
module.exports = {
module.exports = function(config) {
return {
sync: function(){
let instances;
try {
@@ -11,5 +12,6 @@ module.exports = {
instances = [];
}
return instances;
},
}
}
+39 -33
View File
@@ -14,9 +14,8 @@ const sLog = require("single-line-log").stdout;
const query = require('cli-interact').getYesNo;
const fileOps = require("_app/fileOps");
const config = require("./../../config");
// const config = require("./../../config");
const instances = require("./../getInstances.js").sync();
function ellipse(str, max){
return str.length > (max - 3) ? str.substring(0,max-3) + '...' : str;
@@ -24,18 +23,24 @@ function ellipse(str, max){
// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]};
/**
Lists mods for an instance as a table. Warning, handles printing internally.
@param {string} instance - Name of the instance or "shared"
@example
var modManager = require("modManager");
modManager.listMods("testInstance");
// console.logs table of mods installed on instance
modManager.listMods("shared");
// console.logs mods located in /sharedMods as a nice table
*/
module.exports.listMods = function(instance){
module.exports = function(config){
if(!config) config = require("./../../config");
const instances = require("./../getInstances.js")(config).sync();
return {
/**
Lists mods for an instance as a table. Warning, handles printing internally.
@param {string} instance - Name of the instance or "shared"
@example
var modManager = require("modManager");
modManager.listMods("testInstance");
// console.logs table of mods installed on instance
modManager.listMods("shared");
// console.logs mods located in /sharedMods as a nice table
*/
listMods: function(instance){
return new Promise((resolve, reject) => {
if(instance && instances.includes(instance)){
factorioAPI.init(false, config.instanceDirectory+'/'+instance+'/instanceMods', config.instanceDirectory+'/'+instance+'/saves', config.factorio_version);
@@ -92,14 +97,14 @@ module.exports.listMods = function(instance){
console.log(JSON.parse(res.getBody()))
*/
});
}
/**
Searches mods.factorio.com for mods matching a search term and prints
the results to console as a neat looking table
},
/**
Searches mods.factorio.com for mods matching a search term and prints
the results to console as a neat looking table
@param {string} searchTerm What to search for
*/
module.exports.findMods = function(searchTerm){
@param {string} searchTerm What to search for
*/
findMods: function(searchTerm){
return new Promise((resolve, reject) => {
factorioAPI.init(false);
factorioAPI.authenticate({
@@ -127,9 +132,8 @@ module.exports.findMods = function(searchTerm){
reject(new Error(e));
});
});
}
module.exports.addMod = function(term, instance){
},
addMod: function(term, instance){
return new Promise((resolve, reject) => {
if(instance == "shared"){ // modDirectory has to end in /
var modDirectory = "sharedMods/";
@@ -204,8 +208,8 @@ module.exports.addMod = function(term, instance){
reject(new Error("Invalid search term"));
}
});
}
module.exports.removeMod = function removeMod(term, instance, force = false){
},
removeMod: function removeMod(term, instance, force = false){
return new Promise((resolve, reject) => {
if(instance == "shared"){ // modDirectory has to end in /
var modDirectory = "sharedMods/";
@@ -237,16 +241,16 @@ module.exports.removeMod = function removeMod(term, instance, force = false){
reject(new Error("Invalid search term"));
}
});
}
},
// 'https://api.github.com/repos/Danielv123/factorioClusterioMod/releases'
/**
Download mod from github repo by looking for the first binary download in
the latest release, saving it to /sharedMods
// 'https://api.github.com/repos/Danielv123/factorioClusterioMod/releases'
/**
Download mod from github repo by looking for the first binary download in
the latest release, saving it to /sharedMods
@param {string} url a github repo URL, for example https://api.github.com/repos/Danielv123/factorioClusterioMod/releases. Must link to /releases
*/
module.exports.downloadFromGitURL = function(url){
@param {string} url a github repo URL, for example https://api.github.com/repos/Danielv123/factorioClusterioMod/releases. Must link to /releases
*/
downloadFromGitURL: function(url){
console.log("Downloading mod from "+url);
// get JSON data about releases
let res = syncRequest('GET', url, {"headers":{"User-Agent":"Please don't require setting a user agent"}});
@@ -261,6 +265,8 @@ module.exports.downloadFromGitURL = function(url){
console.log("Downloaded "+name);
});
}
},
}
}
/*
module.exports.findUpdates = function(){
+6 -4
View File
@@ -52,7 +52,7 @@ const stringUtils = require("./lib/stringUtils");
const fileOps = require("_app/fileOps");
// homemade express middleware for token auth
const authenticate = require("./lib/authenticate");
const authenticate = require("./lib/authenticate")(config);
/** Sync */
function randomStringAsBase64Url(size) {
@@ -279,7 +279,9 @@ db.items.removeItem = function(object) {
}
// store slaves and inventory in a .json full of JSON data
process.on('SIGINT', async function () {
process.on('SIGINT', shutdown); // ctrl + c
process.on('SIGHUP', shutdown); // terminal closed
async function shutdown() {
console.log('Ctrl-C...');
let exitStartTime = Date.now();
// set insane limit to slave length, if its longer than this we are probably being ddosed or something
@@ -304,8 +306,8 @@ process.on('SIGINT', async function () {
}
}
console.log("Exited in "+(Date.now()-exitStartTime)+"ms");
process.exit(2);
});
process.exit(0);
}
/**
POST World ID management. Slaves post here to tell the server they exist