2022-04-04 21:36:44 +00:00
|
|
|
/*
|
|
|
|
* 胡桃API Miao-Plugin 封装
|
|
|
|
* https://github.com/DGP-Studio/DGP.Genshin.HutaoAPI
|
|
|
|
*
|
|
|
|
* */
|
|
|
|
|
|
|
|
import fetch from "node-fetch";
|
|
|
|
|
2022-04-18 21:32:21 +00:00
|
|
|
const host = "http://49.232.91.210:88/miaoPlugin/hutaoApi";
|
2022-04-04 21:36:44 +00:00
|
|
|
|
|
|
|
let hutaoApi = null;
|
|
|
|
|
|
|
|
function getApi(api) {
|
2022-04-18 21:32:21 +00:00
|
|
|
return `${host}?api=${api}`;
|
2022-04-04 21:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let HutaoApi = {
|
|
|
|
async req(url, data) {
|
|
|
|
let cacheData = await redis.get(`hutao:${url}`);
|
|
|
|
if (cacheData) {
|
|
|
|
return JSON.parse(cacheData)
|
|
|
|
}
|
|
|
|
|
2022-04-18 21:32:21 +00:00
|
|
|
let response = await fetch(getApi(`${url}`), {
|
2022-04-04 21:36:44 +00:00
|
|
|
method: "GET",
|
|
|
|
});
|
|
|
|
let retData = await response.json();
|
2022-05-04 20:53:20 +00:00
|
|
|
if (retData && retData.data) {
|
|
|
|
let d = new Date();
|
|
|
|
retData.lastUpdate = `${d.toLocaleDateString()} ${d.toTimeString().substr(0, 5)}`;
|
|
|
|
await redis.set(`hutao:${url}`, JSON.stringify(retData), { EX: 3600 });
|
|
|
|
}
|
2022-04-04 21:36:44 +00:00
|
|
|
return retData;
|
|
|
|
},
|
|
|
|
|
|
|
|
// 角色持有及命座分布
|
|
|
|
async getCons() {
|
|
|
|
return await HutaoApi.req("/Statistics/Constellation");
|
|
|
|
},
|
|
|
|
|
|
|
|
async getAbyssPct() {
|
|
|
|
return await HutaoApi.req("/Statistics/AvatarParticipation");
|
2022-05-04 20:53:20 +00:00
|
|
|
},
|
2022-04-04 21:36:44 +00:00
|
|
|
|
2022-05-04 20:53:20 +00:00
|
|
|
async getAbyssTeam() {
|
|
|
|
return await HutaoApi.req("/Statistics/TeamCombination");
|
|
|
|
}
|
2022-04-04 21:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default HutaoApi;
|