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'
|
2022-04-04 21:36:44 +00:00
|
|
|
|
2022-07-30 20:20:10 +00:00
|
|
|
const host = 'http://49.232.91.210:88/miaoPlugin/hutaoApi'
|
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-07-30 20:20:10 +00:00
|
|
|
async req (url, param = {}) {
|
|
|
|
let cacheData = await redis.get(`hutao:${url}`)
|
|
|
|
if (cacheData && param.method !== 'POST') {
|
2022-04-04 21:36:44 +00:00
|
|
|
return JSON.parse(cacheData)
|
|
|
|
}
|
|
|
|
|
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)}`
|
|
|
|
await redis.set(`hutao:${url}`, JSON.stringify(retData), { EX: 3600 })
|
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 () {
|
|
|
|
return await HutaoApi.req('/Statistics/TeamCombination')
|
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-07-30 20:20:10 +00:00
|
|
|
async upload (data) {
|
|
|
|
let body = JSON.stringify(data)
|
|
|
|
return await HutaoApi.req('/Record/Upload', {
|
|
|
|
method: 'POST',
|
2022-07-03 20:51:27 +00:00
|
|
|
headers: {
|
2022-07-30 20:20:10 +00:00
|
|
|
'Content-Type': 'text/json; charset=utf-8'
|
2022-07-03 20:51:27 +00:00
|
|
|
},
|
|
|
|
body
|
2022-07-30 20:20:10 +00:00
|
|
|
})
|
2022-07-07 23:02:25 +00:00
|
|
|
},
|
|
|
|
|
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-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
|