修正 platform 命令

This commit is contained in:
cheney
2026-01-27 15:59:24 +08:00
parent 714572994a
commit d5e12945e1
4 changed files with 16 additions and 48 deletions
+4 -29
View File
@@ -1,6 +1,5 @@
const os = require('os');
const diskusage = require('diskusage-ng');
const { physicalCpuCount } = require('physical-cpu-count');
const si = require('systeminformation');
const { formatBytes } = require("./util/convutil")
const { exec } = require('child_process');
const { promisify } = require('util');
@@ -14,6 +13,7 @@ const readFilePromise = promisify(fs.readFile);
// 获取操作系统信息
async function getOSInfo() {
return {
type: os.type(),
platform: os.platform(),
@@ -26,6 +26,7 @@ async function getOSInfo() {
// 获取 CPU 信息
function getCPUInfo() {
const cpus = os.cpus();
const physicalCpuCount = require('physical-cpu-count')
return {
model: cpus[0].model,
speed: cpus[0].speed,
@@ -47,38 +48,13 @@ function getMemoryInfo() {
});
}
// 获取硬盘信息
async function getDiskInfo() {
try {
const path = os.platform() === 'win32' ? 'C:' : '/';
return new Promise(function (resolve, reject) {
diskusage(path, function (err, usage) {
if (err) {
console.error('Error getting disk information:', err);
reject(err);
}
resolve({
totalSize: usage.total,
freeSize: usage.available,
total : formatBytes(usage.total),
free : formatBytes(usage.available),
});
});
})
} catch (error) {
console.error('Error getting disk information:', error);
return null;
}
}
// 主函数,调用上述函数获取所有信息
async function getAllDeviceInfo() {
const osInfo = await getOSInfo();
const cpuInfo = getCPUInfo();
const memoryInfo = getMemoryInfo();
const diskInfo = await getDiskInfo();
const diskInfo = await si.fsSize();
return {
os: osInfo,
@@ -131,6 +107,5 @@ module.exports = {
getOSInfo,
getCPUInfo,
getMemoryInfo,
getDiskInfo,
getAllDeviceInfo
};