Merge branch 'staging' into small-config

pull/1/head
ansuz 5 years ago
commit 8d509fd6d5

@ -1,8 +1,7 @@
/*jshint esversion: 6 */ /*jshint esversion: 6 */
const BatchRead = require("../batch-read");
const nThen = require("nthen"); const nThen = require("nthen");
const getFolderSize = require("get-folder-size"); const getFolderSize = require("get-folder-size");
//const Util = require("../common-util"); const Util = require("../common-util");
var Fs = require("fs"); var Fs = require("fs");
@ -35,9 +34,8 @@ var shutdown = function (Env, Server, cb) {
// and allow system functionality to restart the server // and allow system functionality to restart the server
}; };
const batchRegisteredUsers = BatchRead("GET_REGISTERED_USERS"); var getRegisteredUsers = function (Env, Server, cb) {
var getRegisteredUsers = function (Env, cb) { Env.batchRegisteredUsers('', cb, function (done) {
batchRegisteredUsers('', cb, function (done) {
var dir = Env.paths.pin; var dir = Env.paths.pin;
var folders; var folders;
var users = 0; var users = 0;
@ -63,9 +61,8 @@ var getRegisteredUsers = function (Env, cb) {
}); });
}; };
const batchDiskUsage = BatchRead("GET_DISK_USAGE"); var getDiskUsage = function (Env, Server, cb) {
var getDiskUsage = function (Env, cb) { Env.batchDiskUsage('', cb, function (done) {
batchDiskUsage('', cb, function (done) {
var data = {}; var data = {};
nThen(function (waitFor) { nThen(function (waitFor) {
getFolderSize('./', waitFor(function(err, info) { getFolderSize('./', waitFor(function(err, info) {
@ -92,31 +89,40 @@ var getDiskUsage = function (Env, cb) {
}); });
}; };
Admin.command = function (Env, safeKey, data, cb, Server) { var getActiveChannelCount = function (Env, Server, cb) {
cb(void 0, Server.getActiveChannelCount());
};
var flushCache = function (Env, Server, cb) {
Env.flushCache();
cb(void 0, true);
};
var commands = {
ACTIVE_SESSIONS: getActiveSessions,
ACTIVE_PADS: getActiveChannelCount,
REGISTERED_USERS: getRegisteredUsers,
DISK_USAGE: getDiskUsage,
FLUSH_CACHE: flushCache,
SHUTDOWN: shutdown,
};
Admin.command = function (Env, safeKey, data, _cb, Server) {
var cb = Util.once(Util.mkAsync(_cb));
var admins = Env.admins; var admins = Env.admins;
//var unsafeKey = Util.unescapeKeyCharacters(safeKey); //var unsafeKey = Util.unescapeKeyCharacters(safeKey);
if (admins.indexOf(safeKey) === -1) { if (admins.indexOf(safeKey) === -1) {
return void cb("FORBIDDEN"); return void cb("FORBIDDEN");
} }
// Handle commands here var command = commands[data[0]];
switch (data[0]) {
case 'ACTIVE_SESSIONS': if (typeof(command) === 'function') {
return getActiveSessions(Env, Server, cb); return void command(Env, Server, cb);
case 'ACTIVE_PADS':
return cb(void 0, Server.getActiveChannelCount());
case 'REGISTERED_USERS':
return getRegisteredUsers(Env, cb);
case 'DISK_USAGE':
return getDiskUsage(Env, cb);
case 'FLUSH_CACHE':
Env.flushCache();
return cb(void 0, true);
case 'SHUTDOWN':
return shutdown(Env, Server, cb);
default:
return cb('UNHANDLED_ADMIN_COMMAND');
} }
return void cb('UNHANDLED_ADMIN_COMMAND');
}; };

@ -37,8 +37,11 @@ module.exports.create = function (config, cb) {
metadata_cache: {}, metadata_cache: {},
channel_cache: {}, channel_cache: {},
queueStorage: WriteQueue(), queueStorage: WriteQueue(),
batchIndexReads: BatchRead("HK_GET_INDEX"), batchIndexReads: BatchRead("HK_GET_INDEX"),
batchMetadata: BatchRead('GET_METADATA'), batchMetadata: BatchRead('GET_METADATA'),
batchRegisteredUsers: BatchRead("GET_REGISTERED_USERS"),
batchDiskUsage: BatchRead('GET_DISK_USAGE'),
//historyKeeper: config.historyKeeper, //historyKeeper: config.historyKeeper,
intervals: config.intervals || {}, intervals: config.intervals || {},

Loading…
Cancel
Save