code cleanup
This commit is contained in:
parent
4adca87c60
commit
ac6b0125bd
10
lib/audio.js
10
lib/audio.js
@ -17,7 +17,7 @@ const exec = require('child_process').exec;
|
|||||||
const execSync = require('child_process').execSync;
|
const execSync = require('child_process').execSync;
|
||||||
const util = require('./util');
|
const util = require('./util');
|
||||||
|
|
||||||
let _platform = process.platform;
|
const _platform = process.platform;
|
||||||
|
|
||||||
const _linux = _platform === 'linux' || _platform === 'android';
|
const _linux = _platform === 'linux' || _platform === 'android';
|
||||||
const _darwin = _platform === 'darwin';
|
const _darwin = _platform === 'darwin';
|
||||||
@ -83,8 +83,8 @@ function parseAudioType(str, input, output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLinuxAudioPci() {
|
function getLinuxAudioPci() {
|
||||||
let cmd = 'lspci -v 2>/dev/null';
|
const cmd = 'lspci -v 2>/dev/null';
|
||||||
let result = [];
|
const result = [];
|
||||||
try {
|
try {
|
||||||
const parts = execSync(cmd, util.execOptsLinux).toString().split('\n\n');
|
const parts = execSync(cmd, util.execOptsLinux).toString().split('\n\n');
|
||||||
parts.forEach((element) => {
|
parts.forEach((element) => {
|
||||||
@ -97,7 +97,7 @@ function getLinuxAudioPci() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,7 +239,7 @@ function audio(callback) {
|
|||||||
result.push(audio);
|
result.push(audio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch {
|
||||||
util.noop();
|
util.noop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ const util = require('./util');
|
|||||||
const bluetoothVendors = require('./bluetoothVendors');
|
const bluetoothVendors = require('./bluetoothVendors');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
let _platform = process.platform;
|
const _platform = process.platform;
|
||||||
|
|
||||||
const _linux = _platform === 'linux' || _platform === 'android';
|
const _linux = _platform === 'linux' || _platform === 'android';
|
||||||
const _darwin = _platform === 'darwin';
|
const _darwin = _platform === 'darwin';
|
||||||
@ -187,7 +187,7 @@ function bluetoothDevices(callback) {
|
|||||||
result[i].connected = true;
|
result[i].connected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch {
|
||||||
util.noop();
|
util.noop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,10 +16,10 @@
|
|||||||
const util = require('./util');
|
const util = require('./util');
|
||||||
const DockerSocket = require('./dockerSocket');
|
const DockerSocket = require('./dockerSocket');
|
||||||
|
|
||||||
let _platform = process.platform;
|
const _platform = process.platform;
|
||||||
const _windows = _platform === 'win32';
|
const _windows = _platform === 'win32';
|
||||||
|
|
||||||
let _docker_container_stats = {};
|
const _docker_container_stats = {};
|
||||||
let _docker_socket;
|
let _docker_socket;
|
||||||
let _docker_last_read = 0;
|
let _docker_last_read = 0;
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ function dockerImages(all, callback) {
|
|||||||
try {
|
try {
|
||||||
dockerImages = data;
|
dockerImages = data;
|
||||||
if (dockerImages && Object.prototype.toString.call(dockerImages) === '[object Array]' && dockerImages.length > 0) {
|
if (dockerImages && Object.prototype.toString.call(dockerImages) === '[object Array]' && dockerImages.length > 0) {
|
||||||
dockerImages.forEach(function (element) {
|
dockerImages.forEach((element) => {
|
||||||
if (element.Names && Object.prototype.toString.call(element.Names) === '[object Array]' && element.Names.length > 0) {
|
if (element.Names && Object.prototype.toString.call(element.Names) === '[object Array]' && element.Names.length > 0) {
|
||||||
element.Name = element.Names[0].replace(/^\/|\/$/g, '');
|
element.Name = element.Names[0].replace(/^\/|\/$/g, '');
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ function dockerImages(all, callback) {
|
|||||||
}
|
}
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(result);
|
callback(result);
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ function dockerImagesInspect(imageID, payload) {
|
|||||||
config: data.Config ? data.Config : {},
|
config: data.Config ? data.Config : {},
|
||||||
rootFS: data.RootFS ? data.RootFS : {}
|
rootFS: data.RootFS ? data.RootFS : {}
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -208,7 +208,7 @@ exports.dockerImages = dockerImages;
|
|||||||
|
|
||||||
function dockerContainers(all, callback) {
|
function dockerContainers(all, callback) {
|
||||||
function inContainers(containers, id) {
|
function inContainers(containers, id) {
|
||||||
let filtered = containers.filter((obj) => {
|
const filtered = containers.filter((obj) => {
|
||||||
/**
|
/**
|
||||||
* @namespace
|
* @namespace
|
||||||
* @property {string} Id
|
* @property {string} Id
|
||||||
@ -253,7 +253,7 @@ function dockerContainers(all, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
docker_containers.forEach(function (element) {
|
docker_containers.forEach((element) => {
|
||||||
if (element.Names && Object.prototype.toString.call(element.Names) === '[object Array]' && element.Names.length > 0) {
|
if (element.Names && Object.prototype.toString.call(element.Names) === '[object Array]' && element.Names.length > 0) {
|
||||||
element.Name = element.Names[0].replace(/^\/|\/$/g, '');
|
element.Name = element.Names[0].replace(/^\/|\/$/g, '');
|
||||||
}
|
}
|
||||||
@ -336,7 +336,7 @@ function dockerContainerInspect(containerID, payload) {
|
|||||||
// hostconfig: payload.HostConfig,
|
// hostconfig: payload.HostConfig,
|
||||||
// network: payload.NetworkSettings
|
// network: payload.NetworkSettings
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -408,7 +408,7 @@ function docker_calcNetworkIO(networks) {
|
|||||||
* @property {number} rx_bytes
|
* @property {number} rx_bytes
|
||||||
* @property {number} tx_bytes
|
* @property {number} tx_bytes
|
||||||
*/
|
*/
|
||||||
let obj = networks[key];
|
const obj = networks[key];
|
||||||
rx = +obj.rx_bytes;
|
rx = +obj.rx_bytes;
|
||||||
wx = +obj.tx_bytes;
|
wx = +obj.tx_bytes;
|
||||||
}
|
}
|
||||||
@ -434,7 +434,7 @@ function docker_calcBlockIO(blkio_stats) {
|
|||||||
Object.prototype.toString.call(blkio_stats.io_service_bytes_recursive) === '[object Array]' &&
|
Object.prototype.toString.call(blkio_stats.io_service_bytes_recursive) === '[object Array]' &&
|
||||||
blkio_stats.io_service_bytes_recursive.length > 0
|
blkio_stats.io_service_bytes_recursive.length > 0
|
||||||
) {
|
) {
|
||||||
blkio_stats.io_service_bytes_recursive.forEach(function (element) {
|
blkio_stats.io_service_bytes_recursive.forEach((element) => {
|
||||||
/**
|
/**
|
||||||
* @namespace
|
* @namespace
|
||||||
* @property {string} op
|
* @property {string} op
|
||||||
@ -552,7 +552,7 @@ function dockerContainerStats(containerIDs, callback) {
|
|||||||
|
|
||||||
function dockerContainerStatsSingle(containerID) {
|
function dockerContainerStatsSingle(containerID) {
|
||||||
containerID = containerID || '';
|
containerID = containerID || '';
|
||||||
let result = {
|
const result = {
|
||||||
id: containerID,
|
id: containerID,
|
||||||
memUsage: 0,
|
memUsage: 0,
|
||||||
memLimit: 0,
|
memLimit: 0,
|
||||||
@ -606,13 +606,13 @@ function dockerContainerStatsSingle(containerID) {
|
|||||||
result.memoryStats = stats.memory_stats ? stats.memory_stats : {};
|
result.memoryStats = stats.memory_stats ? stats.memory_stats : {};
|
||||||
result.networks = stats.networks ? stats.networks : {};
|
result.networks = stats.networks ? stats.networks : {};
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch {
|
||||||
util.noop();
|
util.noop();
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch {
|
||||||
util.noop();
|
util.noop();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -688,7 +688,7 @@ function dockerContainerProcesses(containerID, callback) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch {
|
||||||
util.noop();
|
util.noop();
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
@ -720,7 +720,7 @@ function dockerVolumes(callback) {
|
|||||||
try {
|
try {
|
||||||
dockerVolumes = data;
|
dockerVolumes = data;
|
||||||
if (dockerVolumes && dockerVolumes.Volumes && Object.prototype.toString.call(dockerVolumes.Volumes) === '[object Array]' && dockerVolumes.Volumes.length > 0) {
|
if (dockerVolumes && dockerVolumes.Volumes && Object.prototype.toString.call(dockerVolumes.Volumes) === '[object Array]' && dockerVolumes.Volumes.length > 0) {
|
||||||
dockerVolumes.Volumes.forEach(function (element) {
|
dockerVolumes.Volumes.forEach((element) => {
|
||||||
result.push({
|
result.push({
|
||||||
name: element.Name,
|
name: element.Name,
|
||||||
driver: element.Driver,
|
driver: element.Driver,
|
||||||
@ -741,7 +741,7 @@ function dockerVolumes(callback) {
|
|||||||
}
|
}
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(result);
|
callback(result);
|
||||||
}
|
}
|
||||||
@ -760,7 +760,7 @@ function dockerAll(callback) {
|
|||||||
dockerContainers(true).then((result) => {
|
dockerContainers(true).then((result) => {
|
||||||
if (result && Object.prototype.toString.call(result) === '[object Array]' && result.length > 0) {
|
if (result && Object.prototype.toString.call(result) === '[object Array]' && result.length > 0) {
|
||||||
let l = result.length;
|
let l = result.length;
|
||||||
result.forEach(function (element) {
|
result.forEach((element) => {
|
||||||
dockerContainerStats(element.id).then((res) => {
|
dockerContainerStats(element.id).then((res) => {
|
||||||
// include stats in array
|
// include stats in array
|
||||||
element.memUsage = res[0].memUsage;
|
element.memUsage = res[0].memUsage;
|
||||||
|
|||||||
@ -701,8 +701,6 @@ function blockDevices(callback) {
|
|||||||
if (_windows) {
|
if (_windows) {
|
||||||
const drivetypes = ['Unknown', 'NoRoot', 'Removable', 'Local', 'Network', 'CD/DVD', 'RAM'];
|
const drivetypes = ['Unknown', 'NoRoot', 'Removable', 'Local', 'Network', 'CD/DVD', 'RAM'];
|
||||||
try {
|
try {
|
||||||
// util.wmic('logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value').then((stdout, error) => {
|
|
||||||
// util.powerShell('Get-CimInstance Win32_logicaldisk | select Caption,DriveType,Name,FileSystem,Size,VolumeSerialNumber,VolumeName | fl').then((stdout, error) => {
|
|
||||||
const workload = [];
|
const workload = [];
|
||||||
workload.push(util.powerShell('Get-CimInstance -ClassName Win32_LogicalDisk | select Caption,DriveType,Name,FileSystem,Size,VolumeSerialNumber,VolumeName | fl'));
|
workload.push(util.powerShell('Get-CimInstance -ClassName Win32_LogicalDisk | select Caption,DriveType,Name,FileSystem,Size,VolumeSerialNumber,VolumeName | fl'));
|
||||||
workload.push(
|
workload.push(
|
||||||
|
|||||||
40
lib/util.js
40
lib/util.js
@ -21,7 +21,7 @@ const exec = require('child_process').exec;
|
|||||||
const execSync = require('child_process').execSync;
|
const execSync = require('child_process').execSync;
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
let _platform = process.platform;
|
const _platform = process.platform;
|
||||||
const _linux = _platform === 'linux' || _platform === 'android';
|
const _linux = _platform === 'linux' || _platform === 'android';
|
||||||
const _darwin = _platform === 'darwin';
|
const _darwin = _platform === 'darwin';
|
||||||
const _windows = _platform === 'win32';
|
const _windows = _platform === 'win32';
|
||||||
@ -30,7 +30,6 @@ const _openbsd = _platform === 'openbsd';
|
|||||||
const _netbsd = _platform === 'netbsd';
|
const _netbsd = _platform === 'netbsd';
|
||||||
|
|
||||||
let _cores = 0;
|
let _cores = 0;
|
||||||
let wmicPath = '';
|
|
||||||
let codepage = '';
|
let codepage = '';
|
||||||
let _smartMonToolsInstalled = null;
|
let _smartMonToolsInstalled = null;
|
||||||
let _rpi_cpuinfo = null;
|
let _rpi_cpuinfo = null;
|
||||||
@ -40,7 +39,7 @@ const WINDIR = process.env.WINDIR || 'C:\\Windows';
|
|||||||
// powerShell
|
// powerShell
|
||||||
let _psChild;
|
let _psChild;
|
||||||
let _psResult = '';
|
let _psResult = '';
|
||||||
let _psCmds = [];
|
const _psCmds = [];
|
||||||
let _psPersistent = false;
|
let _psPersistent = false;
|
||||||
let _powerShell = '';
|
let _powerShell = '';
|
||||||
const _psToUTF8 = '$OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8 ; ';
|
const _psToUTF8 = '$OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8 ; ';
|
||||||
@ -364,39 +363,6 @@ function getPowershell() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWmic() {
|
|
||||||
if (os.type() === 'Windows_NT' && !wmicPath) {
|
|
||||||
wmicPath = WINDIR + '\\system32\\wbem\\wmic.exe';
|
|
||||||
if (!fs.existsSync(wmicPath)) {
|
|
||||||
try {
|
|
||||||
const wmicPathArray = execSync('WHERE WMIC', execOptsWin).toString().split('\r\n');
|
|
||||||
if (wmicPathArray && wmicPathArray.length) {
|
|
||||||
wmicPath = wmicPathArray[0];
|
|
||||||
} else {
|
|
||||||
wmicPath = 'wmic';
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
wmicPath = 'wmic';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return wmicPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
function wmic(command) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
process.nextTick(() => {
|
|
||||||
try {
|
|
||||||
powerShell(getWmic() + ' ' + command).then((stdout) => {
|
|
||||||
resolve(stdout, '');
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
resolve('', e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getVboxmanage() {
|
function getVboxmanage() {
|
||||||
return _windows ? `"${process.env.VBOX_INSTALL_PATH || process.env.VBOX_MSI_INSTALL_PATH}\\VBoxManage.exe"` : 'vboxmanage';
|
return _windows ? `"${process.env.VBOX_INSTALL_PATH || process.env.VBOX_MSI_INSTALL_PATH}\\VBoxManage.exe"` : 'vboxmanage';
|
||||||
}
|
}
|
||||||
@ -2673,8 +2639,6 @@ exports.decodeEscapeSequence = decodeEscapeSequence;
|
|||||||
exports.parseDateTime = parseDateTime;
|
exports.parseDateTime = parseDateTime;
|
||||||
exports.parseHead = parseHead;
|
exports.parseHead = parseHead;
|
||||||
exports.findObjectByKey = findObjectByKey;
|
exports.findObjectByKey = findObjectByKey;
|
||||||
exports.getWmic = getWmic;
|
|
||||||
exports.wmic = wmic;
|
|
||||||
exports.darwinXcodeExists = darwinXcodeExists;
|
exports.darwinXcodeExists = darwinXcodeExists;
|
||||||
exports.getVboxmanage = getVboxmanage;
|
exports.getVboxmanage = getVboxmanage;
|
||||||
exports.powerShell = powerShell;
|
exports.powerShell = powerShell;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user