forked from HuanLinOTO/GenshinCloudGameHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
135 lines (127 loc) · 4.66 KB
/
config.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const { exit } = require("process")
const fs = require("fs")
const request = require("sync-request")
const nodemailer = require('nodemailer')
exports.NotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?status=NotificationStatusUnread&type=NotificationTypePopup&is_sort=true'
exports.WalletURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get'
exports.AnnouncementURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/getAnnouncementInfo'
exports.AppVersionURL = 'https://api-cloudgame-static.mihoyo.com/hk4e_cg_cn/gamer/api/getFunctionShieldNew?client_type=1'
exports.Notification = function(header) {
let tmp = JSON.parse(request("GET",exports.NotificationURL,{
headers:header
}).body.toString());
tmp.StringVersion = JSON.stringify(tmp);
return tmp;
}
exports.Wallet = function(header) {
let tmp = JSON.parse(request("GET",exports.WalletURL,{
headers:header
}).body.toString());
tmp.StringVersion = JSON.stringify(tmp);
return tmp;
}
exports.Announcement = function(header) {
let tmp = JSON.parse(request("GET",exports.AnnouncementURL,{
headers:header
}).body.toString());
tmp.StringVersion = JSON.stringify(tmp);
return tmp;
}
exports.AppVersion = function() {
let tmp = JSON.parse(request("GET",exports.AppVersionURL).body.toString());
tmp.StringVersion = JSON.stringify(tmp);
return tmp;
}
var configKeys = [
"token",
"client_type",
"device_name",
"device_model",
"sys_version",
"channel"
]
exports.getGlobalConfig = function() {
try {
var globalConfig = fs.readFileSync("global.json")
} catch(e) {
if(e == "Error: ENOENT: no such file or directory, scandir 'global.json'") {
log.error(`读取配置失败!找不到全局配置文件`)
} else {
log.error(`读取配置失败!错误信息:${e}`);
}
exit()
}
return JSON.parse(globalConfig);
}
exports.getConfigs = function(){
// var configsList;
try {
var configsList = fs.readdirSync("configs")
} catch(e) {
if(e == "Error: ENOENT: no such file or directory, scandir 'configs'") {
log.error(`读取配置失败!找不到configs文件夹`)
} else {
log.error(`读取配置失败!错误信息:${e}`);
}
exit()
}
log.info(`检测到${configsList.length}个配置文件:`)
configsList.forEach(file => {
log.info(`${file}`)
})
var configs = {}
configsList.forEach(file => {
configs[file] = JSON.parse(fs.readFileSync(`configs/${file}`))
})
return configs
}
exports.checkConfigs = function(configs){
for(file in configs) {
var configThis = configs[file];
var isNoProbem = true;
for(key in configKeys) {
if(configThis[configKeys[key]] == "" || configThis[configKeys[key]] == undefined || configThis[configKeys[key]] == null || configThis[configKeys[key]] == NaN) {
log.error(`配置文件 ${file} 异常:`);
log.error(` —— ${configKeys[key]}字段缺失`);
isNoProbem = false;
break;
}
}
if(!isNoProbem) {
exit();
}
}
}
// var appversion = exports.AppVersion();
exports.makeHeader = function(data,appversion){
return {
'x-rpc-combo_token': data.token,
'x-rpc-client_type': data.client_type,
'x-rpc-app_version': appversion,
'x-rpc-sys_version': data.sys_version,
'x-rpc-channel': data.channel,
'x-rpc-device_id': data.device_id,
'x-rpc-device_name': data.device_name,
'x-rpc-device_model': data.device_model,
'x-rpc-app_id': 1953439974,
'Referer': 'https://app.mihoyo.com',
'Host': 'api-cloudgame.mihoyo.com',
'Connection': 'Keep-Alive',
'Accept-Encoding': 'gzip',
'User-Agent': 'okhttp/4.9.0'
}
}
exports.SendLog = function(transporter,mailfrom,mailto,successNum,totalNum,content) {
transporter.sendMail({
from: mailfrom+'" Genshin CloudPlay Helper"', //邮件来源
to: mailto, //邮件发送到哪里,多个邮箱使用逗号隔开
subject: `今日已签到${successNum}/${totalNum}名用户`, // 邮件主题
text: '☺️😍😎', // 存文本类型的邮件正文
html: `${content}` // html类型的邮件正文
}, (error, info) => {
if (error) {
return console.log(error);
}
log.info("日志已丢出!")
});
}