Skip to content

Commit

Permalink
make app more robust in regard to MULTI command, refs #358
Browse files Browse the repository at this point in the history
  • Loading branch information
sseide committed Jul 5, 2019
1 parent c909d17 commit 766f949
Showing 1 changed file with 54 additions and 40 deletions.
94 changes: 54 additions & 40 deletions lib/routes/apiv1.js
Expand Up @@ -265,6 +265,11 @@ function postExec (req, res) {
}
}

// block MULTI command as long as no support implemented. breaks to much things currently
if (commandName === 'multi') {
return res.send('ERROR: Command MULTI not supported');
}

let args = parts.slice(1);
args.push(function (err, results) {
if (err) {
Expand Down Expand Up @@ -1111,51 +1116,60 @@ function getKeysTree (req, res, next) {

let lookup = {};
let reducedKeys = [];
keys.forEach(function (key) {
let fullKey = key;
if (prefix) {
key = key.substr(prefix.length);
}
let parts = key.split(foldingCharacter);
let firstPart = "";

// attn: key may begin with folding char - then add string after folding char too
// otherwise will get endless loop with ui
// distinguish between entire key starting with foldingchar and subkey having multiple
// foldingchars next to each other (e.g. :main vs main::sub)
if (key.startsWith(foldingCharacter) && !prefix) {
parts.shift(); // remove empty first entry due to key starting with foldingchar
firstPart = foldingCharacter;
}
firstPart += parts[0];
if (parts.length > 1) {
firstPart += foldingCharacter;
}

if (lookup.hasOwnProperty(firstPart)) {
lookup[firstPart].count++;
} else {
// must provide unique id over all connections for jstree to work correctly
let nodeId = '';
try {
keys.forEach(function(key) {
let fullKey = key;
if (prefix) {
nodeId = res.locals.connectionId + ":" + prefix + firstPart;
key = key.substr(prefix.length);
}
else {
nodeId = res.locals.connectionId + ":" + firstPart;
let parts = key.split(foldingCharacter);
let firstPart = "";

// attn: key may begin with folding char - then add string after folding char too
// otherwise will get endless loop with ui
// distinguish between entire key starting with foldingchar and subkey having multiple
// foldingchars next to each other (e.g. :main vs main::sub)
if (key.startsWith(foldingCharacter) && !prefix) {
parts.shift(); // remove empty first entry due to key starting with foldingchar
firstPart = foldingCharacter;
}
lookup[firstPart] = {
id: nodeId,
text: firstPart,
count: parts.length === 1 ? 0 : 1,
keyName: firstPart,
fullKey: fullKey
};
if (parts.length !== 1) {
lookup[firstPart].children = true;
firstPart += parts[0];
if (parts.length > 1) {
firstPart += foldingCharacter;
}
reducedKeys.push(lookup[firstPart]);
}
});

if (lookup.hasOwnProperty(firstPart)) {
lookup[firstPart].count++;
}
else {
// must provide unique id over all connections for jstree to work correctly
let nodeId = '';
if (prefix) {
nodeId = res.locals.connectionId + ":" + prefix + firstPart;
}
else {
nodeId = res.locals.connectionId + ":" + firstPart;
}
lookup[firstPart] = {
id: nodeId,
text: firstPart,
count: parts.length === 1 ? 0 : 1,
keyName: firstPart,
fullKey: fullKey
};
if (parts.length !== 1) {
lookup[firstPart].children = true;
}
reducedKeys.push(lookup[firstPart]);
}
});
}
catch (e) {
console.log(`Cannot group keys for treeview, used MULTI command before? - ` + e.message);
res.status(400).send({success: false, message: 'Error getting sub keys for this tree' + e.message});
return;
}

reducedKeys.forEach(function (data) {
if (data.count !== 0) {
Expand Down

0 comments on commit 766f949

Please sign in to comment.