code cleanup

This commit is contained in:
Sebastian Hildebrandt 2026-01-08 18:59:06 +01:00
parent 4adca87c60
commit ac6b0125bd
5 changed files with 26 additions and 64 deletions

View File

@ -17,7 +17,7 @@ const exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const util = require('./util');
let _platform = process.platform;
const _platform = process.platform;
const _linux = _platform === 'linux' || _platform === 'android';
const _darwin = _platform === 'darwin';
@ -83,8 +83,8 @@ function parseAudioType(str, input, output) {
}
function getLinuxAudioPci() {
let cmd = 'lspci -v 2>/dev/null';
let result = [];
const cmd = 'lspci -v 2>/dev/null';
const result = [];
try {
const parts = execSync(cmd, util.execOptsLinux).toString().split('\n\n');
parts.forEach((element) => {
@ -97,7 +97,7 @@ function getLinuxAudioPci() {
}
});
return result;
} catch (e) {
} catch {
return result;
}
}
@ -239,7 +239,7 @@ function audio(callback) {
result.push(audio);
}
}
} catch (e) {
} catch {
util.noop();
}
}

View File

@ -20,7 +20,7 @@ const util = require('./util');
const bluetoothVendors = require('./bluetoothVendors');
const fs = require('fs');
let _platform = process.platform;
const _platform = process.platform;
const _linux = _platform === 'linux' || _platform === 'android';
const _darwin = _platform === 'darwin';
@ -187,7 +187,7 @@ function bluetoothDevices(callback) {
result[i].connected = true;
}
}
} catch (e) {
} catch {
util.noop();
}

View File

@ -16,10 +16,10 @@
const util = require('./util');
const DockerSocket = require('./dockerSocket');
let _platform = process.platform;
const _platform = process.platform;
const _windows = _platform === 'win32';
let _docker_container_stats = {};
const _docker_container_stats = {};
let _docker_socket;
let _docker_last_read = 0;
@ -119,7 +119,7 @@ function dockerImages(all, callback) {
try {
dockerImages = data;
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) {
element.Name = element.Names[0].replace(/^\/|\/$/g, '');
}
@ -144,7 +144,7 @@ function dockerImages(all, callback) {
}
resolve(result);
}
} catch (err) {
} catch {
if (callback) {
callback(result);
}
@ -193,7 +193,7 @@ function dockerImagesInspect(imageID, payload) {
config: data.Config ? data.Config : {},
rootFS: data.RootFS ? data.RootFS : {}
});
} catch (err) {
} catch {
resolve();
}
});
@ -208,7 +208,7 @@ exports.dockerImages = dockerImages;
function dockerContainers(all, callback) {
function inContainers(containers, id) {
let filtered = containers.filter((obj) => {
const filtered = containers.filter((obj) => {
/**
* @namespace
* @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) {
element.Name = element.Names[0].replace(/^\/|\/$/g, '');
}
@ -336,7 +336,7 @@ function dockerContainerInspect(containerID, payload) {
// hostconfig: payload.HostConfig,
// network: payload.NetworkSettings
});
} catch (err) {
} catch {
resolve();
}
});
@ -408,7 +408,7 @@ function docker_calcNetworkIO(networks) {
* @property {number} rx_bytes
* @property {number} tx_bytes
*/
let obj = networks[key];
const obj = networks[key];
rx = +obj.rx_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]' &&
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
* @property {string} op
@ -552,7 +552,7 @@ function dockerContainerStats(containerIDs, callback) {
function dockerContainerStatsSingle(containerID) {
containerID = containerID || '';
let result = {
const result = {
id: containerID,
memUsage: 0,
memLimit: 0,
@ -606,13 +606,13 @@ function dockerContainerStatsSingle(containerID) {
result.memoryStats = stats.memory_stats ? stats.memory_stats : {};
result.networks = stats.networks ? stats.networks : {};
}
} catch (err) {
} catch {
util.noop();
}
// }
resolve(result);
});
} catch (err) {
} catch {
util.noop();
}
});
@ -688,7 +688,7 @@ function dockerContainerProcesses(containerID, callback) {
});
});
}
} catch (err) {
} catch {
util.noop();
}
if (callback) {
@ -720,7 +720,7 @@ function dockerVolumes(callback) {
try {
dockerVolumes = data;
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({
name: element.Name,
driver: element.Driver,
@ -741,7 +741,7 @@ function dockerVolumes(callback) {
}
resolve(result);
}
} catch (err) {
} catch {
if (callback) {
callback(result);
}
@ -760,7 +760,7 @@ function dockerAll(callback) {
dockerContainers(true).then((result) => {
if (result && Object.prototype.toString.call(result) === '[object Array]' && result.length > 0) {
let l = result.length;
result.forEach(function (element) {
result.forEach((element) => {
dockerContainerStats(element.id).then((res) => {
// include stats in array
element.memUsage = res[0].memUsage;

View File

@ -701,8 +701,6 @@ function blockDevices(callback) {
if (_windows) {
const drivetypes = ['Unknown', 'NoRoot', 'Removable', 'Local', 'Network', 'CD/DVD', 'RAM'];
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 = [];
workload.push(util.powerShell('Get-CimInstance -ClassName Win32_LogicalDisk | select Caption,DriveType,Name,FileSystem,Size,VolumeSerialNumber,VolumeName | fl'));
workload.push(

View File

@ -21,7 +21,7 @@ const exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const util = require('util');
let _platform = process.platform;
const _platform = process.platform;
const _linux = _platform === 'linux' || _platform === 'android';
const _darwin = _platform === 'darwin';
const _windows = _platform === 'win32';
@ -30,7 +30,6 @@ const _openbsd = _platform === 'openbsd';
const _netbsd = _platform === 'netbsd';
let _cores = 0;
let wmicPath = '';
let codepage = '';
let _smartMonToolsInstalled = null;
let _rpi_cpuinfo = null;
@ -40,7 +39,7 @@ const WINDIR = process.env.WINDIR || 'C:\\Windows';
// powerShell
let _psChild;
let _psResult = '';
let _psCmds = [];
const _psCmds = [];
let _psPersistent = false;
let _powerShell = '';
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() {
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.parseHead = parseHead;
exports.findObjectByKey = findObjectByKey;
exports.getWmic = getWmic;
exports.wmic = wmic;
exports.darwinXcodeExists = darwinXcodeExists;
exports.getVboxmanage = getVboxmanage;
exports.powerShell = powerShell;