yz-yuki-plugin 2.0.9-2 → 2.0.9-3
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://
|
|
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();
|
|
@@ -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
|
-
//
|
|
566
|
-
|
|
567
|
-
|
|
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);
|