2022-08-20 23:40:32 +00:00
|
|
|
import lodash from 'lodash'
|
2023-02-09 16:57:25 +00:00
|
|
|
import EnkaData from './EnkaData.js'
|
2023-03-07 17:52:11 +00:00
|
|
|
import { Data } from '#miao'
|
2022-08-04 20:22:51 +00:00
|
|
|
|
2022-11-27 19:35:57 +00:00
|
|
|
let HttpsProxyAgent = ''
|
|
|
|
|
2023-02-09 16:57:25 +00:00
|
|
|
export default {
|
2022-08-18 10:13:42 +00:00
|
|
|
id: 'enka',
|
|
|
|
cfgKey: 'enkaApi',
|
|
|
|
// 处理请求参数
|
|
|
|
async request (api) {
|
2022-09-14 04:25:14 +00:00
|
|
|
let params = {
|
|
|
|
headers: { 'User-Agent': this.getCfg('userAgent') }
|
|
|
|
}
|
2022-08-18 10:13:42 +00:00
|
|
|
let proxy = this.getCfg('proxyAgent')
|
|
|
|
if (proxy) {
|
2022-11-27 19:35:57 +00:00
|
|
|
if (HttpsProxyAgent === '') {
|
|
|
|
HttpsProxyAgent = await import('https-proxy-agent').catch((err) => {
|
|
|
|
logger.error(err)
|
|
|
|
})
|
2024-05-04 03:19:41 +00:00
|
|
|
HttpsProxyAgent = HttpsProxyAgent ? HttpsProxyAgent.default : undefined
|
2022-11-27 19:35:57 +00:00
|
|
|
}
|
|
|
|
if (HttpsProxyAgent) {
|
|
|
|
params.agent = new HttpsProxyAgent(proxy)
|
|
|
|
}
|
2022-08-03 17:01:00 +00:00
|
|
|
}
|
2022-08-18 10:13:42 +00:00
|
|
|
return { api, params }
|
|
|
|
},
|
|
|
|
|
|
|
|
// 处理服务返回
|
|
|
|
async response (data, req) {
|
2022-06-14 22:07:24 +00:00
|
|
|
if (!data.playerInfo) {
|
2022-09-14 19:31:10 +00:00
|
|
|
if (data.error) {
|
2022-09-14 04:25:14 +00:00
|
|
|
console.log(`Enka ReqErr: ${data.error}`)
|
|
|
|
}
|
2022-08-22 13:38:34 +00:00
|
|
|
return req.err('error', 60)
|
2022-06-14 22:07:24 +00:00
|
|
|
}
|
2022-07-27 18:36:49 +00:00
|
|
|
let details = data.avatarInfoList
|
2022-06-14 22:07:24 +00:00
|
|
|
if (!details || details.length === 0 || !details[0].propMap) {
|
2022-08-19 02:42:03 +00:00
|
|
|
return req.err('empty', 5 * 60)
|
2022-06-14 22:07:24 +00:00
|
|
|
}
|
2022-08-20 23:40:32 +00:00
|
|
|
return data
|
|
|
|
},
|
|
|
|
|
2023-02-09 16:57:25 +00:00
|
|
|
updatePlayer (player, data) {
|
|
|
|
player.setBasicData(Data.getData(data, 'name:nickname,face:profilePicture.avatarID,card:nameCardID,level,word:worldLevel,sign:signature'))
|
|
|
|
lodash.forEach(data.avatarInfoList, (ds) => {
|
|
|
|
let ret = EnkaData.setAvatar(player, ds)
|
|
|
|
if (ret) {
|
|
|
|
player._update.push(ret.id)
|
|
|
|
}
|
|
|
|
})
|
2022-08-20 23:40:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// 获取冷却时间
|
|
|
|
cdTime (data) {
|
|
|
|
return data.ttl || 60
|
2022-06-14 22:07:24 +00:00
|
|
|
}
|
2023-02-09 16:57:25 +00:00
|
|
|
}
|