From 4ed3555f339564b501ced275deaf088f8b4e87f4 Mon Sep 17 00:00:00 2001 From: bietiaop <1527109126@qq.com> Date: Mon, 15 Jul 2024 15:58:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ck=E6=8F=90=E7=A4=BA;=E6=8A=BD=E5=8D=A1?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/panel.js | 4 ++++ lib/mysapi.js | 4 +++- lib/plugin.js | 40 ++++++++++++++++++++++------------------ utils/data.js | 1 + 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/apps/panel.js b/apps/panel.js index 799c014..519662f 100644 --- a/apps/panel.js +++ b/apps/panel.js @@ -44,6 +44,10 @@ export class Panel extends ZZZPlugin { await this.reply('正在刷新面板列表,请稍候...'); await this.getPlayerInfo(); const result = await refreshPanel(this.e, api, uid, deviceFp); + if (!result) { + await this.reply('面板列表刷新失败,请稍后再试'); + return; + } const newChar = result.filter(item => item.isNew); let str = '面板列表获取成功,本次共刷新了' + newChar.length + '个角色:\n'; for (const item of result) { diff --git a/lib/mysapi.js b/lib/mysapi.js index df93d62..f36e5a0 100644 --- a/lib/mysapi.js +++ b/lib/mysapi.js @@ -30,7 +30,9 @@ export default class MysZZZApi extends MysApi { const ck = Object.values(this.cookie).find(item => { return item.ck && item.uid === uid; }); - logger.debug(ck); + if (!ck) { + throw new Error(`[ZZZ]要查询的UID:${uid}未绑定Cookie`); + } this._device = ck?.device_id || ck?.device; this.cookie = ck?.ck; } diff --git a/lib/plugin.js b/lib/plugin.js index a6e9a0c..64eaa14 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -50,27 +50,31 @@ export class ZZZPlugin extends plugin { return false; } - // 创建米游社 API 对象 - const api = new MysZZZApi(uid, ck); - // 获取设备指纹 - let deviceFp = await redis.get(`ZZZ:DEVICE_FP:${uid}`); - if (!deviceFp) { - const sdk = api.getUrl('getFp'); - const res = await fetch(sdk.url, { - headers: sdk.headers, - method: 'POST', - body: sdk.body, - }); - const fpRes = await res.json(); - deviceFp = fpRes?.data?.device_fp; - if (deviceFp) { - await redis.set(`ZZZ:DEVICE_FP:${uid}`, deviceFp, { - EX: 86400 * 7, + try { + // 创建米游社 API 对象 + const api = new MysZZZApi(uid, ck); + // 获取设备指纹 + let deviceFp = await redis.get(`ZZZ:DEVICE_FP:${uid}`); + if (!deviceFp) { + const sdk = api.getUrl('getFp'); + const res = await fetch(sdk.url, { + headers: sdk.headers, + method: 'POST', + body: sdk.body, }); + const fpRes = await res.json(); + deviceFp = fpRes?.data?.device_fp; + if (deviceFp) { + await redis.set(`ZZZ:DEVICE_FP:${uid}`, deviceFp, { + EX: 86400 * 7, + }); + } } + // 返回数据(API、UID、设备指纹) + return { api, uid, deviceFp }; + } catch (error) { + this.reply(error.message); } - // 返回数据(API、UID、设备指纹) - return { api, uid, deviceFp }; } /** diff --git a/utils/data.js b/utils/data.js index 910c25c..5f8450d 100644 --- a/utils/data.js +++ b/utils/data.js @@ -1,3 +1,4 @@ +import _ from 'lodash'; /** * 生成随机字符串 * @param {number} length 长度