2022-04-04 21:36:44 +00:00
|
|
|
/*
|
|
|
|
* 胡桃API Miao-Plugin 封装
|
|
|
|
* https://github.com/DGP-Studio/DGP.Genshin.HutaoAPI
|
|
|
|
*
|
|
|
|
* */
|
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
import fetch from 'node-fetch'
|
2023-03-07 17:52:11 +00:00
|
|
|
import { Data } from '#miao'
|
2022-04-04 21:36:44 +00:00
|
|
|
|
2023-06-06 20:45:52 +00:00
|
|
|
const host = 'http://miao.games/api/hutao'
|
2022-04-04 21:36:44 +00:00
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
function getApi (api) {
|
|
|
|
return `${host}?api=${api}`
|
2022-04-04 21:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let HutaoApi = {
|
2022-09-04 21:03:23 +00:00
|
|
|
async req (url, param = {}, EX = 3600) {
|
2022-09-18 20:54:01 +00:00
|
|
|
let cacheData = await Data.getCacheJSON(`miao:hutao:${url}`)
|
2022-09-04 21:03:23 +00:00
|
|
|
if (cacheData && cacheData.data && param.method !== 'POST') {
|
2022-09-04 09:33:14 +00:00
|
|
|
return cacheData
|
2022-04-04 21:36:44 +00:00
|
|
|
}
|
2022-04-18 21:32:21 +00:00
|
|
|
let response = await fetch(getApi(`${url}`), {
|
2022-07-03 20:51:27 +00:00
|
|
|
...param,
|
2022-07-30 20:20:10 +00:00
|
|
|
method: param.method || 'GET'
|
|
|
|
})
|
|
|
|
let retData = await response.json()
|
|
|
|
if (retData && retData.data && param.method !== 'POST') {
|
|
|
|
let d = new Date()
|
|
|
|
retData.lastUpdate = `${d.toLocaleDateString()} ${d.toTimeString().substr(0, 5)}`
|
2022-09-18 20:54:01 +00:00
|
|
|
await Data.setCacheJSON(`miao:hutao:${url}`, retData, EX)
|
2022-05-04 20:53:20 +00:00
|
|
|
}
|
2022-07-30 20:20:10 +00:00
|
|
|
return retData
|
2022-04-04 21:36:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// 角色持有及命座分布
|
2022-07-30 20:20:10 +00:00
|
|
|
async getCons () {
|
|
|
|
return await HutaoApi.req('/Statistics/Constellation')
|
2022-04-04 21:36:44 +00:00
|
|
|
},
|
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
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-07-30 20:20:10 +00:00
|
|
|
async getAbyssUse () {
|
|
|
|
return await HutaoApi.req('/Statistics2/AvatarParticipation')
|
2022-07-08 21:49:29 +00:00
|
|
|
},
|
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
async getAbyssTeam () {
|
2022-10-22 19:45:28 +00:00
|
|
|
return await HutaoApi.req('/Statistics/Team/Combination')
|
2022-07-03 20:51:27 +00:00
|
|
|
},
|
|
|
|
|
2022-08-06 22:36:05 +00:00
|
|
|
async getOverview () {
|
|
|
|
return await HutaoApi.req('/Statistics/Overview')
|
|
|
|
},
|
|
|
|
|
2022-10-22 19:45:28 +00:00
|
|
|
async getUsage () {
|
|
|
|
return await HutaoApi.req('/Statistics/Avatar/AvatarCollocation')
|
|
|
|
},
|
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
async uploadData (data = {}) {
|
|
|
|
let body = JSON.stringify(data)
|
|
|
|
return await HutaoApi.req('/Record/UploadData', {
|
|
|
|
method: 'POST',
|
2022-07-07 23:02:25 +00:00
|
|
|
headers: {
|
2022-10-22 19:45:28 +00:00
|
|
|
'User-Agent': 'Yunzai-Bot/Miao-Plugin',
|
2022-07-30 20:20:10 +00:00
|
|
|
'Content-Type': 'text/json; charset=utf-8'
|
2022-07-07 23:02:25 +00:00
|
|
|
},
|
|
|
|
body
|
2022-07-30 20:20:10 +00:00
|
|
|
})
|
2022-05-04 20:53:20 +00:00
|
|
|
}
|
2022-07-30 20:20:10 +00:00
|
|
|
}
|
2022-04-04 21:36:44 +00:00
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
export default HutaoApi
|