mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Improved performance of /api/getFactorioLocale with caching
This commit is contained in:
1 parent
2aff63e4a1
commit
6a7042c0aa
2 files changed
+18
-10
No files matched your search
@@ -6,6 +6,8 @@ Module for grabbing factorio locale from a local factorio install
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const ini = require("ini");
|
const ini = require("ini");
|
||||||
|
|
||||||
|
const cache = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gets raw factorio locale from the .ini file.
|
Gets raw factorio locale from the .ini file.
|
||||||
Not available outside of module through exports.
|
Not available outside of module through exports.
|
||||||
@@ -32,14 +34,20 @@ Gets factorios locale as an object, does not respect mods.
|
|||||||
*/
|
*/
|
||||||
module.exports.asObject = function getLocaleAsObject(factorioDirectory, languageCode, callback){
|
module.exports.asObject = function getLocaleAsObject(factorioDirectory, languageCode, callback){
|
||||||
if(typeof factorioDirectory != "string" || typeof languageCode != "string" || typeof callback != "function"){
|
if(typeof factorioDirectory != "string" || typeof languageCode != "string" || typeof callback != "function"){
|
||||||
throw "Error: wrong parameters provided";
|
throw new Error("Error: wrong parameters provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!cache[languageCode]){
|
||||||
|
getLocale(factorioDirectory, languageCode, (err, rawLocale) => {
|
||||||
|
if(err){
|
||||||
|
callback(err);
|
||||||
|
} else {
|
||||||
|
let processedLocale = ini.parse(rawLocale);
|
||||||
|
cache[languageCode] = processedLocale;
|
||||||
|
callback(undefined, processedLocale);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(undefined, cache[languageCode]);
|
||||||
}
|
}
|
||||||
getLocale(factorioDirectory, languageCode, (err, rawLocale) => {
|
|
||||||
if(err){
|
|
||||||
callback(err);
|
|
||||||
} else {
|
|
||||||
let processedLocale = ini.parse(rawLocale)
|
|
||||||
callback(undefined, processedLocale);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
@@ -782,7 +782,7 @@ Requires x-access-token header to be set. Find you api token in secret-api-token
|
|||||||
@memberof clusterioMaster
|
@memberof clusterioMaster
|
||||||
@instance
|
@instance
|
||||||
@alias api/runCommand
|
@alias api/runCommand
|
||||||
@param {object} JSON {instanceID:19412312, command:"/c game.print('hello')"}
|
@param {object} JSON {instanceID:19412312, broadcast:false, command:"/c game.print('hello')"}
|
||||||
@returns {object} Status {auth: bool, message: "Informative error", data:{}}
|
@returns {object} Status {auth: bool, message: "Informative error", data:{}}
|
||||||
*/
|
*/
|
||||||
app.post("/api/runCommand", (req,res) => {
|
app.post("/api/runCommand", (req,res) => {
|
||||||
|
|||||||
Reference in new issue
Block a user