1
0
Fork 0
auth.rxbn.de/bin/cli/cmds/cache_handler.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-06-17 00:28:44 +00:00
/*
* This file is part of the authRXBN single sign-on package.
*
* (c) Ruben Meyer <contact@rxbn.de>
*/
module.exports = {
'command': 'cache [action] [type]',
'description': 'do something with the cache',
'actionDependencies': ['vorpal'],
'action': (actionDependencies) => {
let vorpal = actionDependencies.vorpal;
return (args, cb) => {
if(typeof args.action !== 'undefined') {
let action = args.action.toLowerCase();
if(typeof args.type !== 'undefined') { var type = args.type.toLowerCase(); }
else { var type = ''; }
//Object.keys(args.options).length > 0
if(action == 'help' || action == '?') {
vorpal.exec('cache --help');
}
else if(action == 'flush') {
2019-09-01 19:30:16 +00:00
if(typeof global['gds'].cache[type] !== "undefined") {
global['gds'].cache[type] = {};
2019-06-17 00:28:44 +00:00
console.log(type+' cache flush');
} else if(type == 'all') {
2019-09-01 19:30:16 +00:00
global['gds'].cache = {};
2019-06-17 00:28:44 +00:00
console.log('full cache flush');
}
else vorpal.exec('cache --help');
}
else if(action == 'get') {
2019-09-01 19:30:16 +00:00
console.log(Object.keys(global['gds'].cache));
2019-06-17 00:28:44 +00:00
console.log(type);
2019-09-01 19:30:16 +00:00
console.log(type in Object.keys(global['gds'].cache));
console.log(Object.keys(global['gds'].cache).hasOwnProperty(type));
if(typeof global['gds'].cache[type] !== "undefined") {
console.log(JSON.stringify(global['gds'].cache[type]));
2019-06-17 00:28:44 +00:00
} else if(type == 'all'){
2019-09-01 19:30:16 +00:00
console.log(JSON.stringify(global['gds'].cache));
2019-06-17 00:28:44 +00:00
} else {
console.log("The cache \""+type+"\" doesnt exists.");
vorpal.exec('cache --help');
}
} else vorpal.exec('cache --help');
} else vorpal.exec('cache --help');
cb();
}
}
};