-
Notifications
You must be signed in to change notification settings - Fork 0
/
disk.js
46 lines (40 loc) · 1.21 KB
/
disk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var diskspace = require('diskspace');
var osType = require('os').type();
// 磁盘信息
var m_nFreeBytes = 0; //空闲容量
var m_nTotalBytes = 0; //总容量
var m_diskPath; //存储位置
function checkDiskInfo () {
console.log('store disk is ' + m_diskPath);
diskspace.check(m_diskPath, function (err, result) {
m_nTotalBytes = result.total;
m_nFreeBytes = result.free;
});
}
module.exports.set_disk_path = function (disk_path) {
if (osType === 'Windows_NT') {
m_diskPath = disk_path[0];
} else {
m_diskPath = disk_path;
}
checkDiskInfo();
};
module.exports.get_disk_info = function (check) {
if(check)
setImmediate(checkDiskInfo); //重新获取磁盘信息
return {
free_bytes : m_nFreeBytes,
total_bytes : m_nTotalBytes
};
};
//检查能否处理上传图片请求
module.exports.add_state = function (err) {
//磁盘剩余空间 1G = 1024*1024*1024
if (m_nFreeBytes < 1073741824) {
console.log("free space is ",m_nFreeBytes);
err = "free space is " + m_nFreeBytes;
return false;
}
return true;
};
console.log('run disk.js');