2023-10-20 21:57:43 +08:00
|
|
|
|
const { exit } = require("process");
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
const { default: axios } = require("axios");
|
|
|
|
|
const { log } = require("./util");
|
2023-08-27 20:02:57 +08:00
|
|
|
|
|
2023-10-20 21:57:43 +08:00
|
|
|
|
exports.ListNotificationURL =
|
|
|
|
|
"https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?is_sort=true&source=NotificationSourceUnknown&status=NotificationStatusUnread&type=NotificationTypePopup";
|
|
|
|
|
exports.AckNotificationURL =
|
|
|
|
|
"https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/ackNotification";
|
|
|
|
|
exports.WalletURL =
|
|
|
|
|
"https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get?cost_method=COST_METHOD_UNSPECIFIED";
|
|
|
|
|
exports.AnnouncementURL =
|
|
|
|
|
"https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/getAnnouncementInfo";
|
2023-08-27 20:02:57 +08:00
|
|
|
|
// Here must be an earlier version so that the response won't be null
|
2023-10-20 21:57:43 +08:00
|
|
|
|
exports.AppVersionURL =
|
|
|
|
|
"https://api-takumi.mihoyo.com/ptolemaios/api/getLatestRelease?app_id=1953443910&app_version=3.8.0&channel=mihoyo";
|
2023-08-27 20:02:57 +08:00
|
|
|
|
|
2023-10-20 21:57:43 +08:00
|
|
|
|
exports.ListNotification = async function (header) {
|
|
|
|
|
let tmp = (
|
|
|
|
|
await axios(exports.ListNotificationURL, {
|
|
|
|
|
headers: header,
|
|
|
|
|
})
|
|
|
|
|
).data;
|
2023-08-27 20:02:57 +08:00
|
|
|
|
tmp.StringVersion = JSON.stringify(tmp);
|
|
|
|
|
return tmp;
|
2023-10-20 21:57:43 +08:00
|
|
|
|
};
|
|
|
|
|
exports.AckNotification = async function (header, id) {
|
2023-08-27 23:23:19 +08:00
|
|
|
|
let data = `{"id":"${id}"}`;
|
2023-10-20 21:57:43 +08:00
|
|
|
|
await axios.post(exports.AckNotificationURL, data, {
|
|
|
|
|
headers: header,
|
2023-08-27 23:23:19 +08:00
|
|
|
|
});
|
2023-10-20 21:57:43 +08:00
|
|
|
|
};
|
|
|
|
|
exports.Wallet = async function (header) {
|
|
|
|
|
let tmp = (
|
|
|
|
|
await axios(exports.WalletURL, {
|
|
|
|
|
headers: header,
|
|
|
|
|
})
|
|
|
|
|
).data;
|
2023-08-27 20:02:57 +08:00
|
|
|
|
tmp.StringVersion = JSON.stringify(tmp);
|
|
|
|
|
return tmp;
|
2023-10-20 21:57:43 +08:00
|
|
|
|
};
|
|
|
|
|
exports.Announcement = async function (header) {
|
|
|
|
|
let tmp = (
|
|
|
|
|
await axios(exports.AnnouncementURL, {
|
|
|
|
|
headers: header,
|
|
|
|
|
})
|
|
|
|
|
).data;
|
2023-08-27 20:02:57 +08:00
|
|
|
|
tmp.StringVersion = JSON.stringify(tmp);
|
|
|
|
|
return tmp;
|
2023-10-20 21:57:43 +08:00
|
|
|
|
};
|
|
|
|
|
exports.AppVersion = async function () {
|
2023-08-27 22:15:01 +08:00
|
|
|
|
let tmp = (await axios(exports.AppVersionURL)).data;
|
2023-08-27 20:02:57 +08:00
|
|
|
|
tmp.StringVersion = JSON.stringify(tmp);
|
|
|
|
|
return tmp;
|
2023-10-20 21:57:43 +08:00
|
|
|
|
};
|
2023-08-27 20:02:57 +08:00
|
|
|
|
var configKeys = [
|
|
|
|
|
"token",
|
|
|
|
|
"client_type",
|
|
|
|
|
"device_name",
|
|
|
|
|
"device_model",
|
|
|
|
|
"sys_version",
|
2023-10-20 21:57:43 +08:00
|
|
|
|
"channel",
|
|
|
|
|
];
|
2023-08-27 20:02:57 +08:00
|
|
|
|
|
2023-10-20 21:57:43 +08:00
|
|
|
|
exports.getGlobalConfig = function () {
|
2023-08-27 20:02:57 +08:00
|
|
|
|
try {
|
2023-10-20 21:57:43 +08:00
|
|
|
|
var globalConfig = fs.readFileSync("global.json");
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e.toString().includes("Error: ENOENT: no such file or directory")) {
|
2023-10-20 22:46:48 +08:00
|
|
|
|
log.error(`读取配置失败!找不到全局配置文件`);
|
2023-08-27 20:02:57 +08:00
|
|
|
|
} else {
|
2023-10-20 22:46:48 +08:00
|
|
|
|
log.error(`读取配置失败!错误信息:${e}`);
|
2023-08-27 20:02:57 +08:00
|
|
|
|
}
|
2023-10-20 21:57:43 +08:00
|
|
|
|
exit();
|
2023-08-27 20:02:57 +08:00
|
|
|
|
}
|
|
|
|
|
return JSON.parse(globalConfig);
|
2023-10-20 21:57:43 +08:00
|
|
|
|
};
|
2023-08-27 20:02:57 +08:00
|
|
|
|
|
2023-10-20 21:57:43 +08:00
|
|
|
|
exports.getConfigs = function () {
|
2023-08-27 20:02:57 +08:00
|
|
|
|
try {
|
2023-10-20 21:57:43 +08:00
|
|
|
|
var configsList = fs.readdirSync("configs");
|
2023-10-20 22:42:54 +08:00
|
|
|
|
configsList = configsList.filter((file) => file.endsWith(".json"));
|
2023-10-20 21:57:43 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
if (
|
|
|
|
|
e == "Error: ENOENT: no such file or directory, scandir 'configs'"
|
|
|
|
|
) {
|
2023-10-20 22:46:48 +08:00
|
|
|
|
log.error(`读取配置失败!找不到configs文件夹`);
|
2023-08-27 20:02:57 +08:00
|
|
|
|
} else {
|
2023-10-20 22:46:48 +08:00
|
|
|
|
log.error(`读取配置失败!错误信息:${e}`);
|
2023-08-27 20:02:57 +08:00
|
|
|
|
}
|
2023-10-20 21:57:43 +08:00
|
|
|
|
exit();
|
2023-08-27 20:02:57 +08:00
|
|
|
|
}
|
2023-10-20 21:57:43 +08:00
|
|
|
|
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) {
|
2023-08-27 20:02:57 +08:00
|
|
|
|
var configThis = configs[file];
|
2023-10-20 21:57:43 +08:00
|
|
|
|
for (key in configKeys) {
|
|
|
|
|
if (
|
|
|
|
|
configThis[configKeys[key]] == "" ||
|
|
|
|
|
configThis[configKeys[key]] == undefined ||
|
|
|
|
|
configThis[configKeys[key]] == null ||
|
|
|
|
|
configThis[configKeys[key]] == NaN
|
|
|
|
|
) {
|
2023-08-27 20:02:57 +08:00
|
|
|
|
log.error(`配置文件 ${file} 异常:`);
|
|
|
|
|
log.error(` —— ${configKeys[key]}字段缺失`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-20 21:57:43 +08:00
|
|
|
|
};
|
2023-08-27 20:02:57 +08:00
|
|
|
|
|
2023-10-20 21:57:43 +08:00
|
|
|
|
exports.makeHeader = function (data, appversion) {
|
2023-08-27 20:02:57 +08:00
|
|
|
|
return {
|
2023-08-27 22:55:03 +08:00
|
|
|
|
"x-rpc-combo_token": data.token,
|
2023-10-20 21:57:43 +08:00
|
|
|
|
"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,
|
|
|
|
|
"x-rpc-cg_game_biz": "hk4e_cn",
|
|
|
|
|
"x-rpc-preview": 0,
|
|
|
|
|
"x-rpc-op_biz": "clgm_cn",
|
|
|
|
|
"x-rpc-language": "zh-cn",
|
|
|
|
|
"x-rpc-vendor_id": 2,
|
|
|
|
|
Referer: "https://app.mihoyo.com",
|
|
|
|
|
Host: "api-cloudgame.mihoyo.com",
|
|
|
|
|
Connection: "Keep-Alive",
|
|
|
|
|
"Accept-Encoding": "gzip, deflate",
|
|
|
|
|
Accept: "*/*",
|
|
|
|
|
};
|
|
|
|
|
};
|
2023-08-27 20:02:57 +08:00
|
|
|
|
|
2023-10-20 21:57:43 +08:00
|
|
|
|
exports.SendLog = function (
|
|
|
|
|
transporter,
|
|
|
|
|
mailfrom,
|
|
|
|
|
mailto,
|
|
|
|
|
successNum,
|
|
|
|
|
totalNum,
|
|
|
|
|
content
|
|
|
|
|
) {
|
|
|
|
|
transporter.sendMail(
|
|
|
|
|
{
|
|
|
|
|
from: `"Genshin Cloud Game Helper" <${mailfrom}>`, //邮件来源
|
|
|
|
|
to: mailto, //邮件发送到哪里,多个邮箱使用逗号隔开
|
|
|
|
|
subject: `今日已签到${successNum}/${totalNum}名用户`, // 邮件主题
|
|
|
|
|
text: "", // 存文本类型的邮件正文
|
|
|
|
|
html: `${content}`, // html类型的邮件正文
|
|
|
|
|
},
|
|
|
|
|
(error) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
return console.log(error);
|
|
|
|
|
}
|
|
|
|
|
log.info("日志已丢出!");
|
2023-08-27 20:02:57 +08:00
|
|
|
|
}
|
2023-10-20 21:57:43 +08:00
|
|
|
|
);
|
|
|
|
|
};
|
2023-10-20 22:33:34 +08:00
|
|
|
|
|
2023-10-20 23:04:16 +08:00
|
|
|
|
exports.SendResult = function (transporter, mailfrom, mailto, content, key) {
|
2023-10-20 22:33:34 +08:00
|
|
|
|
transporter.sendMail(
|
|
|
|
|
{
|
|
|
|
|
from: `"Genshin Cloud Game Helper" <${mailfrom}>`, //邮件来源
|
|
|
|
|
to: mailto, //邮件发送到哪里,多个邮箱使用逗号隔开
|
|
|
|
|
subject: `Genshin Cloud Game Helper`, // 邮件主题
|
|
|
|
|
text: `${content}`, // 存文本类型的邮件正文
|
|
|
|
|
},
|
|
|
|
|
(error) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
return console.log(error);
|
|
|
|
|
}
|
2023-10-20 23:04:16 +08:00
|
|
|
|
log.info(`${key} - 已发送通知至${mailto}`);
|
2023-10-20 22:33:34 +08:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|