yz-yuki-plugin 2.0.9-2 → 2.0.9-4

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.
@@ -174,7 +174,7 @@ class BiliRiskCookie {
174
174
  if (data?.code === 0) {
175
175
  if (data?.data?.code === 0) {
176
176
  // 登录成功,获取 set-cookie header 并写入 Jar
177
- const SESSDATA_expires = await this.getCookieExpiration(jar, 'SESSDATA', 'https://api.bilibili.com');
177
+ const SESSDATA_expires = await this.getCookieExpiration(jar, 'SESSDATA', 'https://passport.bilibili.com');
178
178
  try {
179
179
  if (SESSDATA_expires != null) {
180
180
  const tempCookie = await this.getNewTempCk();
@@ -268,7 +268,7 @@ class BiliRiskCookie {
268
268
  method: 'GET',
269
269
  headers: lodash.merge(BiliApi.BIlIBILI_LOGIN_HEADERS, {
270
270
  'User-agent': BiliApi.BILIBILI_HEADERS['User-Agent'],
271
- 'Cookie': SESSDATA_str ? SESSDATA_str : ''
271
+ 'Cookie': SESSDATA_str ? `SESSDATA=${SESSDATA_str}` : ''
272
272
  }),
273
273
  redirect: 'follow'
274
274
  });
@@ -282,7 +282,7 @@ class BiliRiskCookie {
282
282
  const current_exp = level_info?.current_exp;
283
283
  const next_exp = level_info?.next_exp;
284
284
  const ttl = SESSDATA_expires;
285
- const LoginCookieTTLStr = ttl === -1 ? '永久' : ttl === -2 ? '-' : `${new Date(Date.now() + ttl).toLocaleString()}`;
285
+ const LoginCookieTTLStr = ttl === -1 ? '永久' : ttl === -2 ? '-' : `${new Date(ttl).toLocaleString()}`;
286
286
  e.reply(`~B站账号已登陆~\n有效期至:${LoginCookieTTLStr}。\n昵称:${uname}\nuid:${mid}\n硬币:${money}\n经验等级:${current_level}\n当前经验值exp:${current_exp}\n下一等级所需exp:${next_exp}`);
287
287
  return true;
288
288
  }
@@ -356,6 +356,7 @@ class BiliRiskCookie {
356
356
  const { code } = res;
357
357
  switch (code) {
358
358
  case 0:
359
+ await this.resetCookiesAndRedis();
359
360
  e.reply('当前缓存的B站登录CK已在B站服务器退出登录~');
360
361
  break;
361
362
  case 2202:
@@ -562,18 +563,28 @@ class BiliRiskCookie {
562
563
  continue; // 跳过无效的 Cookie
563
564
  if (typeof cookie.value === 'string' && cookie.value.toLowerCase() === 'deleted')
564
565
  continue; // 跳过被删除的 Cookie
565
- // 构造 Redis 键
566
- const redisKey = `${this.prefix}:${cookie.domain}:${cookie.key}`;
567
- let ttl = 0;
566
+ // 统一处理域名,确保大部分API接口都使用 .bilibili.com
567
+ let domain = cookie.domain ? cookie.domain : '.bilibili.com';
568
+ if (domain.startsWith('passport.bilibili.com')) {
569
+ domain = '.bilibili.com';
570
+ }
571
+ else if (!domain.startsWith('.')) {
572
+ domain = `.${domain}`;
573
+ }
574
+ const redisKey = `${this.prefix}:${domain}:${cookie.key}`;
568
575
  // 使用 cookie.TTL() 方法计算 TTL
576
+ let ttl = 0;
569
577
  const ttlInMs = cookie.TTL(); // TTL 返回的是毫秒值
570
- if (ttlInMs > 0) {
578
+ if (ttlInMs && ttlInMs > 0 && isFinite(ttlInMs)) {
571
579
  ttl = Math.floor(ttlInMs / 1000); // 转换为秒
572
580
  }
573
- else if (ttlInMs === 0) {
581
+ else if (ttlInMs === 0 || !isFinite(ttlInMs)) {
574
582
  // 如果 TTL 为 0,表示 Cookie 已过期,跳过存储
575
583
  continue;
576
584
  }
585
+ else {
586
+ ttl = -1;
587
+ }
577
588
  // 构造元数据
578
589
  const meta = JSON.stringify({
579
590
  path: cookie.path,
@@ -581,7 +592,7 @@ class BiliRiskCookie {
581
592
  secure: !!cookie.secure
582
593
  });
583
594
  // 写入 Redis
584
- if (ttl && ttl > 0) {
595
+ if ((ttl && ttl > 0) || ttl === -1) {
585
596
  await Redis.set(redisKey, cookie.value, { EX: ttl }); // 设置键值对,并指定 TTL
586
597
  await Redis.set(`${redisKey}:meta`, meta, { EX: ttl }); // 存储元数据,TTL 与主键一致
587
598
  }
@@ -541,10 +541,6 @@ class WeiboRiskCookie {
541
541
  await Redis.set(redisKey, cookie.value, { EX: ttl });
542
542
  await Redis.set(`${redisKey}:meta`, meta, { EX: ttl });
543
543
  }
544
- else {
545
- await Redis.set(redisKey, cookie.value, { EX: -1 });
546
- await Redis.set(`${redisKey}:meta`, meta, { EX: -1 });
547
- }
548
544
  }
549
545
  catch (error) {
550
546
  logger.warn('Failed to save cookie to Redis:', redisKey, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yz-yuki-plugin",
3
- "version": "2.0.9-2",
3
+ "version": "2.0.9-4",
4
4
  "description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
5
5
  "author": "snowtafir",
6
6
  "type": "module",