yz-yuki-plugin 2.0.6-11 → 2.0.6-13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # 2.0.6
2
+ * 优化api请求
2
3
  * 优化消息发送
3
4
  * 优化文字动态图片资源的发送
4
5
  * 依赖升级
@@ -10,9 +10,9 @@ pushTime: '*/23 * * * *'
10
10
 
11
11
  # 请求头 User-Agent 列表。如出现 -352 风控,可尝试更换请求头,请根据需要自行添加或修改。可设置多个请求头,每次重启后会随机选择一个。获取方法请浏览器自行搜索。
12
12
  userAgentList:
13
- - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
14
- #- Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0
15
- #- Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0
13
+ - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
14
+ #- Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0
15
+ #- Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0
16
16
 
17
17
  # 推送监测间隔,单位为秒,默认7200秒即2小时,即以当前时间为基准,监测过去2小时内的动态,并推送。取值范围:3600-36000秒,即过去的1-10h。应大于pushTime的周期。
18
18
  interval: 7200
@@ -4,8 +4,8 @@ import { Messages, Redis } from 'yunzaijs';
4
4
  import { BiliQuery } from '../models/bilibili/bilibili.main.query.js';
5
5
  import { BiliTask } from '../models/bilibili/bilibili.main.task.js';
6
6
  import Config from '../utils/config.js';
7
- import { BiliGetWebData } from '../models/bilibili/bilibili.main.get.web.data.js';
8
- import { applyLoginQRCode, pollLoginQRCode, saveLoginCookie, postGateway, exitBiliLogin, checkBiliLogin, readSavedCookieItems, saveLocalBiliCk, readSyncCookie, getNewTempCk, saveTempCk } from '../models/bilibili/bilibili.main.models.js';
7
+ import { BilibiliWebDataFetcher } from '../models/bilibili/bilibili.main.get.web.data.js';
8
+ import { readLoginCookie, applyLoginQRCode, pollLoginQRCode, saveLoginCookie, postGateway, exitBiliLogin, checkBiliLogin, readSavedCookieItems, saveLocalBiliCk, readSyncCookie, getNewTempCk, saveTempCk } from '../models/bilibili/bilibili.main.models.js';
9
9
 
10
10
  const message = new Messages('message');
11
11
  let biliPushData = Config.getConfigData('config', 'bilibili', 'push');
@@ -52,8 +52,8 @@ message.use(async (e) => {
52
52
  return;
53
53
  }
54
54
  // 获取 Bilibili 动态信息
55
- const res = await new BiliGetWebData(e).getBiliDynamicListDataByUid(uid);
56
- if (res.statusText !== 'OK') {
55
+ const res = await new BilibiliWebDataFetcher(e).getBiliDynamicListDataByUid(uid);
56
+ if (res?.statusText !== 'OK') {
57
57
  e.reply('出了点网络问题,等会再试试吧~');
58
58
  return false;
59
59
  }
@@ -66,8 +66,8 @@ message.use(async (e) => {
66
66
  let infoName = '';
67
67
  if (code === 0 && has_more === false) {
68
68
  e.reply(`检测到该uid的主页空间动态内容为空,\n执行uid:${uid} 校验...`);
69
- const resp = await new BiliGetWebData(e).getBilibiUserInfoByUid(uid);
70
- if (resp.statusText !== 'OK') {
69
+ const resp = await new BilibiliWebDataFetcher(e).getBilibiUserInfoByUid(uid);
70
+ if (resp?.statusText !== 'OK') {
71
71
  e.reply('出了点网络问题,发起uid校验失败,等会再试试吧~');
72
72
  return false;
73
73
  }
@@ -167,38 +167,44 @@ message.use(async (e) => {
167
167
  }, [/^(#|\/)(yuki|优纪)?(取消|删除|del|DEL)(b站|B站|bili|bilibili|哔哩|哔哩哔哩)推送\s*(视频\s*|图文\s*|文章\s*|转发\s*|直播\s*)*.*$/]);
168
168
  /** 扫码登录B站 */
169
169
  message.use(async (e) => {
170
- if (e.isMaster) {
171
- try {
172
- const token = await applyLoginQRCode(e);
173
- if (token) {
174
- let biliLoginCk = await pollLoginQRCode(e, token);
175
- if (biliLoginCk) {
176
- if (lodash.trim(biliLoginCk).length != 0) {
177
- await saveLoginCookie(e, biliLoginCk);
178
- e.reply(`get bilibili LoginCk:成功!`);
179
- const result = await postGateway(biliLoginCk); //激活ck
180
- const { code, data } = await result.data; // 解析校验结果
181
- switch (code) {
182
- case 0:
183
- global?.logger?.mark(`优纪插件:获取biliLoginCK,Gateway校验成功:${JSON.stringify(data)}`);
184
- break;
185
- default:
186
- global?.logger?.mark(`优纪插件:获取biliLoginCK,Gateway校验失败:${JSON.stringify(data)}`);
187
- break;
170
+ if (!e.isMaster) {
171
+ e.reply('未取得bot主人身份,无权限配置B站登录ck');
172
+ }
173
+ else {
174
+ const LoginCk = await readLoginCookie();
175
+ if (LoginCk) {
176
+ e.reply(`当前已有B站登录ck,请勿重复扫码!\n如需更换,请先删除当前登录再扫码:\n#yuki删除B站登录`);
177
+ }
178
+ else {
179
+ try {
180
+ const token = await applyLoginQRCode(e);
181
+ if (token) {
182
+ let biliLoginCk = await pollLoginQRCode(e, token);
183
+ if (biliLoginCk) {
184
+ if (lodash.trim(biliLoginCk).length != 0) {
185
+ await saveLoginCookie(e, biliLoginCk);
186
+ e.reply(`get bilibili LoginCk:成功!`);
187
+ const result = await postGateway(biliLoginCk); //激活ck
188
+ const { code, data } = await result.data; // 解析校验结果
189
+ switch (code) {
190
+ case 0:
191
+ global?.logger?.mark(`优纪插件:获取biliLoginCK,Gateway校验成功:${JSON.stringify(data)}`);
192
+ break;
193
+ default:
194
+ global?.logger?.mark(`优纪插件:获取biliLoginCK,Gateway校验失败:${JSON.stringify(data)}`);
195
+ break;
196
+ }
197
+ }
198
+ else {
199
+ e.reply(`get bilibili LoginCk:失败X﹏X`);
188
200
  }
189
- }
190
- else {
191
- e.reply(`get bilibili LoginCk:失败X﹏X`);
192
201
  }
193
202
  }
194
203
  }
204
+ catch (Error) {
205
+ global?.logger?.info(`yuki-plugin Login bilibili Failed:${Error}`);
206
+ }
195
207
  }
196
- catch (Error) {
197
- global?.logger?.info(`yuki-plugin Login bilibili Failed:${Error}`);
198
- }
199
- }
200
- else {
201
- e.reply('未取得bot主人身份,无权限配置B站登录ck');
202
208
  }
203
209
  }, [/^(#|\/)(yuki|优纪)?(扫码|添加|ADD|add)(b站|B站|bili|bilibili|哔哩|哔哩哔哩)登录$/]);
204
210
  /** 删除登陆的B站ck */
@@ -432,8 +438,8 @@ message.use(async (e) => {
432
438
  /**通过uid获取up主信息 */
433
439
  message.use(async (e) => {
434
440
  let uid = e.msg.replace(/^(#|\/)(yuki|优纪)?(b站|B站|bili|bilibili|哔哩|哔哩哔哩)(up|UP)主/g, '').trim();
435
- const res = await new BiliGetWebData(e).getBilibiUserInfoByUid(uid);
436
- if (res.statusText !== 'OK') {
441
+ const res = await new BilibiliWebDataFetcher(e).getBilibiUserInfoByUid(uid);
442
+ if (res?.statusText !== 'OK') {
437
443
  e.reply('诶嘿,出了点网络问题,等会再试试吧~');
438
444
  return;
439
445
  }
@@ -460,8 +466,8 @@ message.use(async (e) => {
460
466
  /** 根据名称搜索up的uid*/
461
467
  message.use(async (e) => {
462
468
  let keyword = e.msg.replace(/^(#|\/)(yuki|优纪)?搜索(b站|B站|bili|bilibili|哔哩|哔哩哔哩)(up|UP)主/g, '').trim();
463
- const res = await new BiliGetWebData(e).searchBiliUserInfoByKeyword(keyword);
464
- if (res.statusText !== 'OK') {
469
+ const res = await new BilibiliWebDataFetcher(e).searchBiliUserInfoByKeyword(keyword);
470
+ if (res?.statusText !== 'OK') {
465
471
  e.reply('诶嘿,出了点网络问题,等会再试试吧~');
466
472
  return;
467
473
  }
package/lib/apps/weibo.js CHANGED
@@ -2,7 +2,7 @@ import { Messages } from 'yunzaijs';
2
2
  import { WeiboQuery } from '../models/weibo/weibo.main.query.js';
3
3
  import { WeiboTask } from '../models/weibo/weibo.main.task.js';
4
4
  import Config from '../utils/config.js';
5
- import { WeiboGetWebData } from '../models/weibo/weibo.main.get.web.data.js';
5
+ import { WeiboWebDataFetcher } from '../models/weibo/weibo.main.get.web.data.js';
6
6
 
7
7
  const message = new Messages('message');
8
8
  let weiboPushData = Config.getConfigData('config', 'weibo', 'push');
@@ -46,8 +46,8 @@ message.use(async (e) => {
46
46
  return;
47
47
  }
48
48
  // 获取 微博 博主信息
49
- const res = await new WeiboGetWebData(e).getBloggerInfo(uid);
50
- if (res.statusText !== 'OK') {
49
+ const res = await new WeiboWebDataFetcher(e).getBloggerInfo(uid);
50
+ if (res?.statusText !== 'OK') {
51
51
  e.reply('出了点网络问题,等会再试试吧~');
52
52
  return false;
53
53
  }
@@ -58,7 +58,7 @@ message.use(async (e) => {
58
58
  }
59
59
  const userInfo = data.userInfo || {};
60
60
  let name = uid;
61
- if (userInfo.length !== 0) {
61
+ if (userInfo && userInfo.length !== 0) {
62
62
  name = userInfo.screen_name || uid;
63
63
  }
64
64
  // 添加新的推送数据
@@ -211,8 +211,8 @@ message.use(async (e) => {
211
211
  /**通过uid获取up主信息 */
212
212
  message.use(async (e) => {
213
213
  let uid = e.msg.replace(/^(#|\/)(yuki|优纪)?(微博|weibo|WEIBO)(博|bo|BO)主/g, '').trim();
214
- const res = await new WeiboGetWebData(e).getBloggerInfo(uid);
215
- if (res.statusText !== 'OK') {
214
+ const res = await new WeiboWebDataFetcher(e).getBloggerInfo(uid);
215
+ if (res?.statusText !== 'OK') {
216
216
  e.reply('诶嘿,出了点网络问题,等会再试试吧~');
217
217
  return;
218
218
  }
@@ -240,8 +240,8 @@ message.use(async (e) => {
240
240
  /** 根据昵称搜索博主信息*/
241
241
  message.use(async (e) => {
242
242
  let keyword = e.msg.replace(/^(#|\/)(yuki|优纪)?搜索(微博|weibo|WEIBO)(博|bo|BO)主/g, '').trim();
243
- const res = await new WeiboGetWebData(e).searchBloggerInfo(keyword);
244
- if (res.statusText !== 'OK') {
243
+ const res = await new WeiboWebDataFetcher(e).searchBloggerInfo(keyword);
244
+ if (res?.statusText !== 'OK') {
245
245
  e.reply('诶嘿,出了点网络问题,等会再试试吧~');
246
246
  return;
247
247
  }
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
- import { ConfigController, BOT_NAME } from 'yunzaijs';
2
+ import { BOT_NAME, ConfigController } from 'yunzaijs';
3
3
  import Config from '../../utils/config.js';
4
4
  import path from 'path';
5
- import { _paths, createRequire } from '../../utils/paths.js';
5
+ import { createRequire, _paths } from '../../utils/paths.js';
6
6
 
7
7
  // Footer.tsx
8
8
  const require = createRequire(import.meta.url);
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { BOT_NAME, ConfigController } from 'yunzaijs';
3
3
  import Config from '../../utils/config.js';
4
4
  import path from 'path';
5
- import { _paths, createRequire } from '../../utils/paths.js';
5
+ import { createRequire, _paths } from '../../utils/paths.js';
6
6
 
7
7
  //help.tsx
8
8
  const require = createRequire(import.meta.url);
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { BOT_NAME, ConfigController } from 'yunzaijs';
3
3
  import Config from '../../utils/config.js';
4
4
  import path from 'path';
5
- import { _paths, createRequire } from '../../utils/paths.js';
5
+ import { createRequire, _paths } from '../../utils/paths.js';
6
6
 
7
7
  const require = createRequire(import.meta.url);
8
8
  const botVersion = ConfigController.package?.version;
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk';
2
- import { applicationOptions, setBotTask, useEvent } from 'yunzaijs';
2
+ import { applicationOptions, useEvent, setBotTask } from 'yunzaijs';
3
3
  import Config from './utils/config.js';
4
4
  import path from 'path';
5
5
  import { _paths } from './utils/paths.js';
@@ -8,7 +8,7 @@ class BiliApi {
8
8
  this.USER_AGENT = BiliApi.BILIBILI_USER_AGENT;
9
9
  this.initialize();
10
10
  }
11
- static BILIBILI_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36';
11
+ static BILIBILI_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36';
12
12
  //初始化User-Agent
13
13
  async initialize() {
14
14
  await this.initUserAgent();
@@ -1,4 +1,5 @@
1
1
  import axios from 'axios';
2
+ import https from 'https';
2
3
  import lodash from 'lodash';
3
4
  import BiliApi from './bilibili.main.api.js';
4
5
  import { readSyncCookie, cookieWithBiliTicket, readSavedCookieItems, readSavedCookieOtherItems } from './bilibili.main.models.js';
@@ -6,8 +7,39 @@ import { getWbiSign } from './bilibili.risk.wbi.js';
6
7
  import { getDmImg } from './bilibili.risk.dm.img.js';
7
8
  import { getWebId } from './bilibili.risk.w_webid.js';
8
9
 
9
- class BiliGetWebData {
10
- constructor(e) { }
10
+ class BiliHttpClient {
11
+ client;
12
+ constructor() {
13
+ this.client = this.initializeClient();
14
+ }
15
+ initializeClient() {
16
+ const httpsAgent = new https.Agent({
17
+ keepAlive: true,
18
+ maxSockets: 100,
19
+ timeout: 20000
20
+ });
21
+ const client = axios.create({
22
+ httpsAgent: httpsAgent,
23
+ timeout: 20000
24
+ });
25
+ return client;
26
+ }
27
+ async request(url, config) {
28
+ try {
29
+ const response = await this.client.request({ url, ...config });
30
+ return response;
31
+ }
32
+ catch (error) {
33
+ console.error('BiliHttpClient Request failed:', error);
34
+ // 重新创建 AxiosInstance
35
+ this.client = this.initializeClient();
36
+ }
37
+ }
38
+ }
39
+ class BilibiliWebDataFetcher extends BiliHttpClient {
40
+ constructor(e) {
41
+ super();
42
+ }
11
43
  /**通过uid获取up动态数据表*/
12
44
  async getBiliDynamicListDataByUid(uid) {
13
45
  const url = BiliApi.BILIBIL_API.biliDynamicInfoList;
@@ -32,7 +64,8 @@ class BiliGetWebData {
32
64
  w_rid: w_rid,
33
65
  wts: time_stamp
34
66
  };
35
- const res = await axios.get(url, {
67
+ const res = await this.request(url, {
68
+ method: 'GET',
36
69
  params,
37
70
  timeout: 10000,
38
71
  headers: lodash.merge(BiliApi.BILIBILI_HEADERS, {
@@ -67,7 +100,8 @@ class BiliGetWebData {
67
100
  w_rid: w_rid,
68
101
  wts: time_stamp
69
102
  };
70
- const res = await axios.get(url, {
103
+ const res = await this.request(url, {
104
+ method: 'GET',
71
105
  params,
72
106
  timeout: 5000,
73
107
  headers: lodash.merge(BiliApi.BILIBILI_HEADERS, {
@@ -97,7 +131,8 @@ class BiliGetWebData {
97
131
  w_rid: w_rid,
98
132
  wts: time_stamp
99
133
  };
100
- const res = await axios.get(url, {
134
+ const res = await this.request(url, {
135
+ method: 'GET',
101
136
  params,
102
137
  timeout: 5000,
103
138
  headers: lodash.merge(BiliApi.BILIBILI_HEADERS, {
@@ -111,4 +146,4 @@ class BiliGetWebData {
111
146
  }
112
147
  }
113
148
 
114
- export { BiliGetWebData };
149
+ export { BilibiliWebDataFetcher };
@@ -6,7 +6,7 @@ import { promisify } from 'node:util';
6
6
  import path from 'path';
7
7
  import QRCode from 'qrcode';
8
8
  import YAML from 'yaml';
9
- import { Segment, Redis } from 'yunzaijs';
9
+ import { Redis, Segment } from 'yunzaijs';
10
10
  import { renderPage } from '../../utils/image.js';
11
11
  import { _paths } from '../../utils/paths.js';
12
12
  import BiliApi from './bilibili.main.api.js';
@@ -144,7 +144,9 @@ async function checkBiliLogin(e) {
144
144
  let current_level = level_info?.current_level;
145
145
  let current_exp = level_info?.current_exp;
146
146
  let next_exp = level_info?.next_exp;
147
- e.reply(`~B站账号已登陆~\n昵称:${uname}\nuid:${mid}\n硬币:${money}\n经验等级:${current_level}\n当前经验值exp:${current_exp}\n下一等级所需exp:${next_exp}`);
147
+ const LoginCookieTTL = await readLoginCookieTTL();
148
+ const LoginCookieTTLStr = LoginCookieTTL === -1 ? '永久' : LoginCookieTTL === -2 ? '-' : `${new Date(Date.now() + LoginCookieTTL * 1000).toLocaleString()}`;
149
+ e.reply(`~B站账号已登陆~\n有效期至:${LoginCookieTTLStr}。\n昵称:${uname}\nuid:${mid}\n硬币:${money}\n经验等级:${current_level}\n当前经验值exp:${current_exp}\n下一等级所需exp:${next_exp}`);
148
150
  }
149
151
  else {
150
152
  // 处理其他情况
@@ -228,6 +230,18 @@ async function readLoginCookie() {
228
230
  const tempCk = await Redis.get(CK_KEY);
229
231
  return tempCk ? tempCk : '';
230
232
  }
233
+ /** 读取扫码登陆后缓存的cookie的有效时间 */
234
+ async function readLoginCookieTTL() {
235
+ const CK_KEY = 'Yz:yuki:bili:loginCookie';
236
+ const tempCk = await Redis.get(CK_KEY);
237
+ if (tempCk) {
238
+ const LoginCookieTTL = await Redis.ttl(CK_KEY);
239
+ return LoginCookieTTL;
240
+ }
241
+ else {
242
+ return -2;
243
+ }
244
+ }
231
245
  /** 读取手动绑定的B站ck */
232
246
  async function readLocalBiliCk() {
233
247
  const dir = path.join(_paths.root, 'data/yuki-plugin/');
@@ -473,4 +487,4 @@ async function cookieWithBiliTicket(cookie) {
473
487
  }
474
488
  }
475
489
 
476
- export { applyLoginQRCode, checkBiliLogin, cookieWithBiliTicket, exitBiliLogin, genUUID, gen_b_lsid, getNewTempCk, get_buvid_fp, pollLoginQRCode, postGateway, readSavedCookieItems, readSavedCookieOtherItems, readSyncCookie, readTempCk, saveLocalBiliCk, saveLoginCookie, saveTempCk };
490
+ export { applyLoginQRCode, checkBiliLogin, cookieWithBiliTicket, exitBiliLogin, genUUID, gen_b_lsid, getNewTempCk, get_buvid_fp, pollLoginQRCode, postGateway, readLoginCookie, readSavedCookieItems, readSavedCookieOtherItems, readSyncCookie, readTempCk, saveLocalBiliCk, saveLoginCookie, saveTempCk };
@@ -245,7 +245,7 @@ class BiliQuery {
245
245
  };
246
246
  /**获取完整B站文章内容
247
247
  * @param postUrl - 文章链接: https://www.bilibili.com/read/cvxxxx 或者 https://www.bilibili.com/opus/xxxx
248
- * @returns {Json} 完整的B站文章内容json数据
248
+ * @returns {JSON} 完整的B站文章内容json数据
249
249
  */
250
250
  static async getFullArticleContent(postUrl) {
251
251
  let { cookie } = await readSyncCookie();
@@ -2,7 +2,7 @@ import QRCode from 'qrcode';
2
2
  import { Redis, Segment, Bot } from 'yunzaijs';
3
3
  import Config from '../../utils/config.js';
4
4
  import { renderPage } from '../../utils/image.js';
5
- import { BiliGetWebData } from './bilibili.main.get.web.data.js';
5
+ import { BilibiliWebDataFetcher } from './bilibili.main.get.web.data.js';
6
6
  import { readSyncCookie, postGateway } from './bilibili.main.models.js';
7
7
  import { BiliQuery } from './bilibili.main.query.js';
8
8
 
@@ -10,16 +10,18 @@ class BiliTask {
10
10
  taskName;
11
11
  groupKey;
12
12
  privateKey;
13
+ BilibiliWebDataFetcher;
13
14
  e;
14
15
  constructor(e) {
15
16
  this.taskName = 'biliTask';
16
17
  this.groupKey = 'Yz:yuki:bili:upPush:group:';
17
18
  this.privateKey = 'Yz:yuki:bili:upPush:private:';
19
+ this.BilibiliWebDataFetcher = new BilibiliWebDataFetcher();
18
20
  }
19
21
  async hendleEventDynamicData(uid, count = 0) {
20
22
  let { cookie } = await readSyncCookie();
21
- const resp = await new BiliGetWebData().getBiliDynamicListDataByUid(uid);
22
- const resjson = await resp.data;
23
+ const resp = await this.BilibiliWebDataFetcher.getBiliDynamicListDataByUid(uid);
24
+ const resjson = await resp?.data;
23
25
  if (!resjson || resjson.code !== 0 || resjson.code === -352) {
24
26
  await postGateway(cookie);
25
27
  if (count < 2) {
@@ -1,17 +1,49 @@
1
1
  import axios from 'axios';
2
+ import https from 'https';
2
3
  import { WeiboApi } from './weibo.main.api.js';
3
4
  import { WeiboQuery } from './weibo.main.query.js';
4
5
 
5
- class WeiboGetWebData {
6
+ class WeiboHttpClient {
7
+ client;
8
+ constructor() {
9
+ this.client = this.initializeClient();
10
+ }
11
+ initializeClient() {
12
+ const httpsAgent = new https.Agent({
13
+ keepAlive: true,
14
+ maxSockets: 100,
15
+ timeout: 20000
16
+ });
17
+ const client = axios.create({
18
+ httpsAgent: httpsAgent,
19
+ timeout: 20000
20
+ });
21
+ return client;
22
+ }
23
+ async request(url, config) {
24
+ try {
25
+ const response = await this.client.request({ url, ...config });
26
+ return response;
27
+ }
28
+ catch (error) {
29
+ console.error('WeiboHttpClient Request failed:', error);
30
+ // 重新创建 AxiosInstance
31
+ this.client = this.initializeClient();
32
+ }
33
+ }
34
+ }
35
+ class WeiboWebDataFetcher extends WeiboHttpClient {
6
36
  e;
7
- constructor(e) { }
37
+ constructor(e) {
38
+ super();
39
+ }
8
40
  /**通过uid获取博主信息 */
9
41
  async getBloggerInfo(target) {
10
42
  const param = { containerid: '100505' + target };
11
43
  const url = new URL(WeiboApi.WEIBO_API.weiboGetIndex);
12
44
  url.search = new URLSearchParams(param).toString();
13
- const resp = await axios.get(url.toString(), {
14
- timeout: 10000,
45
+ const resp = await this.request(url.toString(), {
46
+ method: 'GET',
15
47
  headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://m.weibo.cn' }
16
48
  });
17
49
  return resp;
@@ -22,9 +54,9 @@ class WeiboGetWebData {
22
54
  const params = {
23
55
  q: keyword
24
56
  };
25
- const resp = await axios.get(url, {
57
+ const resp = await this.request(url, {
58
+ method: 'GET',
26
59
  params,
27
- timeout: 10000,
28
60
  headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://s.weibo.com' }
29
61
  });
30
62
  return resp;
@@ -36,13 +68,13 @@ class WeiboGetWebData {
36
68
  url.search = new URLSearchParams(params).toString();
37
69
  await new Promise(resolve => setTimeout(resolve, Math.floor(Math.random() * (6500 - 1000 + 1) + 1000)));
38
70
  try {
39
- const response = await axios.get(url.toString(), {
40
- timeout: 15000,
71
+ const response = await this.request(url.toString(), {
72
+ method: 'GET',
41
73
  headers: { 'accept': '*/*', 'Content-Type': 'application/json', 'referer': 'https://m.weibo.cn' }
42
74
  });
43
- const { ok, data, msg } = response.data;
75
+ const { ok, data, msg } = response?.data;
44
76
  if (!ok && msg !== '这里还没有内容') {
45
- throw new Error(response.config.url);
77
+ throw new Error(response?.config.url);
46
78
  }
47
79
  return data.cards.filter(WeiboQuery.filterCardTypeCustom);
48
80
  }
@@ -53,4 +85,4 @@ class WeiboGetWebData {
53
85
  }
54
86
  }
55
87
 
56
- export { WeiboGetWebData };
88
+ export { WeiboWebDataFetcher };
@@ -2,18 +2,20 @@ import QRCode from 'qrcode';
2
2
  import { Redis, Segment, Bot } from 'yunzaijs';
3
3
  import Config from '../../utils/config.js';
4
4
  import { renderPage } from '../../utils/image.js';
5
- import { WeiboGetWebData } from './weibo.main.get.web.data.js';
5
+ import { WeiboWebDataFetcher } from './weibo.main.get.web.data.js';
6
6
  import { WeiboQuery } from './weibo.main.query.js';
7
7
 
8
8
  class WeiboTask {
9
9
  taskName;
10
10
  groupKey;
11
11
  privateKey;
12
+ WeiboWebDataFetcher;
12
13
  e;
13
14
  constructor(e) {
14
15
  this.taskName = 'weiboTask';
15
16
  this.groupKey = 'Yz:yuki:weibo:upPush:group:';
16
17
  this.privateKey = 'Yz:yuki:weibo:upPush:private:';
18
+ this.WeiboWebDataFetcher = new WeiboWebDataFetcher(e);
17
19
  }
18
20
  /**
19
21
  * 执行动态推送任务
@@ -59,7 +61,7 @@ class WeiboTask {
59
61
  dynamicList[subInfoOfup.uid] = dynamicData;
60
62
  }
61
63
  else {
62
- resp = await await new WeiboGetWebData().getBloggerDynamicList(subInfoOfup.uid); // 获取指定 uid 的动态列表
64
+ resp = await this.WeiboWebDataFetcher.getBloggerDynamicList(subInfoOfup.uid); // 获取指定 uid 的动态列表
63
65
  if (resp) {
64
66
  requestedDataOfUids.set(subInfoOfup.uid, resp); // 将响应数据存储到映射中
65
67
  const dynamicData = resp || [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "2.0.6-11",
3
+ "version": "2.0.6-13",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",