Add 'fields' and 'fieldsExtSource' on method info
This commit is contained in:
parent
4bc17d156d
commit
cf50254bae
@ -20,10 +20,46 @@ function parseRq (bytes) {
|
||||
class APIMethods {
|
||||
constructor (parentObj) {
|
||||
this.parentObj = parentObj;
|
||||
this.info.cache = new Object();
|
||||
|
||||
// Clear method cache on update config
|
||||
global.server.on("config.update", () => {
|
||||
this.info.cache = new Object();
|
||||
});
|
||||
}
|
||||
|
||||
info (con, req, cb) {
|
||||
const serverInfo = require("./server-info");
|
||||
if (!req.fields) req.fields = "*";
|
||||
if (!req.fieldsExtSource) req.fieldsExtSource = "*";
|
||||
const cache = this.info.cache[
|
||||
JSON.stringify({
|
||||
f: req.fields, e: req.fieldsExtSource
|
||||
})
|
||||
];
|
||||
|
||||
if (cache) {
|
||||
console.debug("CACHE!");
|
||||
return cb({ result: cache, trace_id: req.trace_id, ended: true });
|
||||
}
|
||||
|
||||
const serverInfo = require("./server-info")();
|
||||
if (req.fields !== "*") {
|
||||
const fields = Object.fromEntries(req.fields.split(/\s*,\s*/g).map(x => [x.trim(), true]));
|
||||
Object.keys(serverInfo).forEach(k => {
|
||||
if (!fields[k]) serverInfo[k] = undefined;
|
||||
});
|
||||
}
|
||||
if (req.fieldsExtSource !== "*" && req.fields.extSource !== undefined) {
|
||||
const fields = Object.fromEntries(req.fieldsExtSource.split(/\s*,\s*/g).map(x => [x.trim(), true]));
|
||||
Object.keys(serverInfo).forEach(k => {
|
||||
if (!fields[k]) serverInfo.extSource[k] = undefined;
|
||||
});
|
||||
}
|
||||
this.info.cache[
|
||||
JSON.stringify({
|
||||
f: req.fields, e: req.fieldsExtSource
|
||||
})
|
||||
] = serverInfo;
|
||||
|
||||
cb({ result: serverInfo, trace_id: req.trace_id, ended: true });
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user