fswin32
Version:
The ultimate Node.js module for detailed Windows file system access.
1 lines • 1.97 kB
JavaScript
// src/info.js\n\nimport { executePowerShellCommand, formatBytes } from \'./utils.js\';\nimport os from \'os\';\n\n/**\n * Gets detailed system information.\n * @returns {Promise<Object>}\n */\nexport const getSystemInfo = async () => {\n const platform = os.platform();\n const release = os.release();\n const arch = os.arch();\n const cpus = os.cpus();\n const totalMemory = os.totalmem();\n const freeMemory = os.freemem();\n\n const systemInfo = {\n platform,\n release,\n arch,\n cpu_cores: cpus.length,\n cpu_model: cpus[0].model,\n total_memory: formatBytes(totalMemory),\n free_memory: formatBytes(freeMemory),\n };\n\n if (platform === \'win32\') {\n const osInfo = await executePowerShellCommand(\'(Get-WmiObject Win32_OperatingSystem).Caption\');\n systemInfo.os_name = osInfo ? osInfo.trim() : \'N/A\';\n }\n\n return systemInfo;\n};\n\n/**\n * Gets disk usage information for all drives.\n * @returns {Promise<Array<Object>>}\n */\nexport const getDiskUsage = async () => {\n const command = \'wmic logicaldisk get size,freespace,caption\';\n const stdout = await executePowerShellCommand(command);\n if (!stdout) {\n return [];\n }\n\n const lines = stdout.split(\'\\n\').slice(1).filter(line => line.trim());\n const usage = lines.map(line => {\n const parts = line.split(/\s+/);\n const drive = parts[0];\n const freeSpace = parseInt(parts[1], 10);\n const totalSpace = parseInt(parts[2], 10);\n const usedSpace = totalSpace - freeSpace;\n\n return {\n drive,\n total_space: formatBytes(totalSpace),\n free_space: formatBytes(freeSpace),\n used_space: formatBytes(usedSpace),\n total_space_bytes: totalSpace,\n free_space_bytes: freeSpace,\n used_space_bytes: usedSpace,\n };\n });\n\n return usage;\n};\n