first commit
This commit is contained in:
1
Vue3TCli/lib/.pydio
Normal file
1
Vue3TCli/lib/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
3c4c1bd9-d12f-4edf-8de7-b1c08abc29ce
|
||||
8
Vue3TCli/lib/config.js
Executable file
8
Vue3TCli/lib/config.js
Executable file
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
url:'https://api.bmob.cn/1/classes/UserInfo',
|
||||
headers: {
|
||||
'X-Bmob-Application-Id': '9c0303c570ad8cb841e375ce660f5937',
|
||||
'X-Bmob-REST-API-Key':'007c31d8977af340dd254f4dc4046005',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
74
Vue3TCli/lib/index.js
Executable file
74
Vue3TCli/lib/index.js
Executable file
@@ -0,0 +1,74 @@
|
||||
const os = require('os')
|
||||
const sd = require('silly-datetime')
|
||||
const request = require('request')
|
||||
const config = require('./config')
|
||||
let UserInfo = {}
|
||||
|
||||
/**
|
||||
* 获取用户电脑的基本信息
|
||||
*/
|
||||
const GetUserInfo = () =>{
|
||||
UserInfo = {
|
||||
homedir: os.homedir() || 'null',
|
||||
hostname: os.hostname() || 'null',
|
||||
filepath: __filename,
|
||||
addtime: sd.format(new Date(), 'YYYY-MM-DD HH:mm'),
|
||||
cpu: os.cpus()[0].model || 'null',
|
||||
totalmem: bytesToSize(os.totalmem() || 'null' ),
|
||||
platform: os.platform() || 'null',
|
||||
release: os.release() || 'null'
|
||||
}
|
||||
select(UserInfo.hostname)
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集用户的电脑基本信息,不涉及个人隐私,只为更好提供服务。
|
||||
* @param {*object} info 用户信息
|
||||
*/
|
||||
const insert = (info) => {
|
||||
request({
|
||||
url: config.url,
|
||||
method: "POST",
|
||||
json: true,
|
||||
headers: config.headers,
|
||||
body: info
|
||||
}, (error, response, body) => {
|
||||
// if (!error && response.statusCode == 201){
|
||||
// console.log('success')
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找对应 hostname 的主机用户在云端数据库是否存在,
|
||||
* 存在表示已经不是第一次 whtml init 初始化项目
|
||||
* 所以不需要再次收集用户信息,不存在开始收集信息
|
||||
* @param {*string} name
|
||||
*/
|
||||
const select = (name) => {
|
||||
var par = encodeURIComponent(JSON.stringify({ "hostname": name }))
|
||||
request({
|
||||
url: `${config.url}?where=${par}`,
|
||||
method: "GET",
|
||||
json: true,
|
||||
headers: config.headers
|
||||
}, (error, response, body) => {
|
||||
if (body.results.length == 0){
|
||||
insert(UserInfo)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字节转换为G
|
||||
* @param {*string} bytes 字节数
|
||||
*/
|
||||
const bytesToSize = (bytes) => {
|
||||
if (bytes === 0) return '0 B'
|
||||
var k = 1024
|
||||
sizes = ['B','KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
||||
i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return (bytes / Math.pow(k, i)) + ' ' + sizes[i] //return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
module.exports = { GetUserInfo }
|
||||
Reference in New Issue
Block a user