🐛 修复管理员存储统计磁盘容量显示为0的问题
- 将存储目录路径从 local-storage 改为 storage,与 storage.js 保持一致 - 添加目录不存在时自动创建的逻辑 - 支持 STORAGE_ROOT 环境变量配置 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3257,14 +3257,19 @@ app.post('/api/admin/settings/test-smtp', authMiddleware, adminMiddleware, async
|
||||
// 获取服务器存储统计信息
|
||||
app.get('/api/admin/storage-stats', authMiddleware, adminMiddleware, async (req, res) => {
|
||||
try {
|
||||
// 获取本地存储目录
|
||||
const localStorageDir = path.join(__dirname, 'local-storage');
|
||||
|
||||
// 获取本地存储目录(与 storage.js 保持一致)
|
||||
const localStorageDir = process.env.STORAGE_ROOT || path.join(__dirname, 'storage');
|
||||
|
||||
// 确保存储目录存在
|
||||
if (!fs.existsSync(localStorageDir)) {
|
||||
fs.mkdirSync(localStorageDir, { recursive: true });
|
||||
}
|
||||
|
||||
// 获取磁盘信息(使用df命令)
|
||||
let totalDisk = 0;
|
||||
let usedDisk = 0;
|
||||
let availableDisk = 0;
|
||||
|
||||
|
||||
try {
|
||||
// 获取本地存储目录所在分区的磁盘信息(避免使用shell)
|
||||
const { stdout: dfOutput } = await execFileAsync('df', ['-B', '1', localStorageDir], { encoding: 'utf8' });
|
||||
@@ -3292,10 +3297,10 @@ app.get('/api/admin/storage-stats', authMiddleware, adminMiddleware, async (req,
|
||||
['logicaldisk', 'where', `DeviceID='${normalizedDrive}:'`, 'get', 'Size,FreeSpace', '/value'],
|
||||
{ encoding: 'utf8' }
|
||||
);
|
||||
|
||||
|
||||
const freeMatch = wmicOutput.match(/FreeSpace=(\d+)/);
|
||||
const sizeMatch = wmicOutput.match(/Size=(\d+)/);
|
||||
|
||||
|
||||
if (sizeMatch && freeMatch) {
|
||||
totalDisk = parseInt(sizeMatch[1]) || 0;
|
||||
availableDisk = parseInt(freeMatch[1]) || 0;
|
||||
|
||||
Reference in New Issue
Block a user