添加使用代理请求enka api配置 (#101)

This commit is contained in:
永恒的小黑屋 2022-08-04 01:01:00 +08:00 committed by GitHub
parent 7108726c56
commit fe0a82dd01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,6 @@
import fetch from 'node-fetch'
import EnkaData from './enka-data.js'
import HttpsProxyAgent from "https-proxy-agent";
let Enka = {
key: 'enka',
cd: 5,
@ -11,8 +11,11 @@ let Enka = {
if (diyCfg?.enkaApi?.apiKey) {
api += '?key=' + diyCfg.enkaApi.apiKey
}
let headers = { headers: { 'User-Agent': diyCfg?.enkaApi?.userAgent || sysCfg.enkaApi.userAgent } }
let req = await fetch(api, headers)
let config = { headers: { 'User-Agent': diyCfg?.enkaApi?.userAgent || sysCfg.enkaApi.userAgent } }
if (diyCfg?.enkaApi?.proxyAgent){
config.agent=new HttpsProxyAgent(diyCfg.enkaApi.proxyAgent)
}
let req = await fetch(api, config)
let data = await req.json()
if (!data.playerInfo) {
e.reply(`请求失败:${data.msg || '可能是面板服务并发过高,请稍后重试'}`)

View File

@ -19,10 +19,13 @@
* 推荐使用广州上海节点如访问enka官网相对稳定的话推荐优先使用官方地址
* 感谢@MiniGrayGay 大佬提供的服务(Github: https://github.com/MiniGrayGay)
*
* 使用代理(科学上网)可以配置proxyAgent
* 例如: http://127.0.0.1:1080
* */
export const enkaApi = {
url: 'https://enka.network/'
url: 'https://enka.network/',
proxyAgent:''
}
/*