From 4654d99f7a547e6e84b63b3dc29edc10c6423a95 Mon Sep 17 00:00:00 2001 From: Kokomi <592981798@qq.com> Date: Wed, 14 Sep 2022 12:25:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4enka=E7=9A=84=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=8F=82=E6=95=B0=EF=BC=8C=E4=BC=98=E5=8C=96=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E9=94=99=E8=AF=AF=E6=97=B6=E7=9A=84=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/profile-data/enka.js | 7 ++++++- models/ProfileReq.js | 14 ++++++++++++-- models/ProfileServ.js | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/components/profile-data/enka.js b/components/profile-data/enka.js index 64bc4230..2b972b93 100644 --- a/components/profile-data/enka.js +++ b/components/profile-data/enka.js @@ -9,7 +9,9 @@ export default new ProfileServ({ // 处理请求参数 async request (api) { - let params = { headers: { 'User-Agent': this.getCfg('userAgent') } } + let params = { + headers: { 'User-Agent': this.getCfg('userAgent') } + } let proxy = this.getCfg('proxyAgent') if (proxy) { let { HttpsProxyAgent } = await Data.import('https-proxy-agent') @@ -21,6 +23,9 @@ export default new ProfileServ({ // 处理服务返回 async response (data, req) { if (!data.playerInfo) { + if(data.error) { + console.log(`Enka ReqErr: ${data.error}`) + } return req.err('error', 60) } let details = data.avatarInfoList diff --git a/models/ProfileReq.js b/models/ProfileReq.js index 0c82ebd9..97053b5b 100644 --- a/models/ProfileReq.js +++ b/models/ProfileReq.js @@ -66,9 +66,19 @@ export default class ProfileReq extends Base { let data = {} try { let params = reqParam.params || {} - params.timeout = params.timeout || 1000 * 10 + params.timeout = params.timeout || 1000 * 20 let req = await fetch(reqParam.url, params) - data = await req.json() + data = await req.text() + if(data[0] === '<'){ + let titleRet = /(.+)<\/title>/.exec(data) + if(titleRet && titleRet[1]) { + data = { error: titleRet[1] } + } else { + return this.err('error', 60) + } + } else { + data = JSON.parse(data) + } } catch (e) { console.log('面板请求错误', e) data = {} diff --git a/models/ProfileServ.js b/models/ProfileServ.js index 3707b65c..4544b642 100644 --- a/models/ProfileServ.js +++ b/models/ProfileServ.js @@ -49,7 +49,7 @@ export default class ProfileServ extends Base { return { url: param.api || api, - param: param.config || {} + params: param.params || {} } }