yz-yuki-plugin 2.0.9-1 → 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
|
}
|
|
@@ -34,7 +34,8 @@ class WeiboWebDataFetcher {
|
|
|
34
34
|
'Host': 'm.weibo.cn',
|
|
35
35
|
'X-XSRF-TOKEN': `${X_XSRF_TOKEN}`,
|
|
36
36
|
'Referer': `https://m.weibo.cn/u/${uid}`
|
|
37
|
-
})
|
|
37
|
+
}),
|
|
38
|
+
responseType: 'json'
|
|
38
39
|
});
|
|
39
40
|
// (3) 获取请求完成后的 Cookie 状态
|
|
40
41
|
const updatedCookies = await new Promise((resolve, reject) => {
|
|
@@ -83,7 +84,8 @@ class WeiboWebDataFetcher {
|
|
|
83
84
|
headers: lodash.merge(WeiboApi.WEIBO_HEADERS, {
|
|
84
85
|
'X-XSRF-TOKEN': `${X_XSRF_TOKEN}`,
|
|
85
86
|
'Referer': 'https://m.weibo.cn/search?'
|
|
86
|
-
})
|
|
87
|
+
}),
|
|
88
|
+
responseType: 'json'
|
|
87
89
|
});
|
|
88
90
|
// (3) 获取请求完成后的 Cookie 状态
|
|
89
91
|
const updatedCookies = await new Promise((resolve, reject) => {
|
|
@@ -135,7 +137,8 @@ class WeiboWebDataFetcher {
|
|
|
135
137
|
'Host': 'm.weibo.cn',
|
|
136
138
|
'X-XSRF-TOKEN': `${X_XSRF_TOKEN}`,
|
|
137
139
|
'referer': `https://m.weibo.cn/u/${uid}`
|
|
138
|
-
})
|
|
140
|
+
}),
|
|
141
|
+
responseType: 'json'
|
|
139
142
|
});
|
|
140
143
|
const { ok, data, msg } = response?.data;
|
|
141
144
|
if (!ok && msg !== '这里还没有内容') {
|
|
@@ -162,7 +165,7 @@ class WeiboWebDataFetcher {
|
|
|
162
165
|
await WeiboCookieManager.saveCookiesToRedis(jar); // 更新同步到 Redis
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
|
-
return data
|
|
168
|
+
return data?.cards.filter(WeiboQuery.filterCardTypeCustom);
|
|
166
169
|
}
|
|
167
170
|
catch (error) {
|
|
168
171
|
logger?.mark('微博推送:Error fetching sub list:', error);
|
|
@@ -519,15 +519,15 @@ class WeiboRiskCookie {
|
|
|
519
519
|
// 计算 TTL(秒)
|
|
520
520
|
let ttl = 0;
|
|
521
521
|
const ttlInMs = cookie.TTL ? cookie.TTL() : 0; // TTL 返回毫秒,可能不存在
|
|
522
|
-
if (ttlInMs > 0) {
|
|
522
|
+
if (ttlInMs && ttlInMs > 0 && isFinite(ttlInMs)) {
|
|
523
523
|
ttl = Math.floor(ttlInMs / 1000);
|
|
524
524
|
}
|
|
525
|
-
else if (ttlInMs === 0) {
|
|
525
|
+
else if (ttlInMs === 0 || !isFinite(ttlInMs)) {
|
|
526
526
|
// 已过期,跳过
|
|
527
527
|
continue;
|
|
528
528
|
}
|
|
529
529
|
else {
|
|
530
|
-
ttl = -1;
|
|
530
|
+
ttl = -1;
|
|
531
531
|
}
|
|
532
532
|
// 构造元数据
|
|
533
533
|
const meta = JSON.stringify({
|
|
@@ -537,14 +537,10 @@ class WeiboRiskCookie {
|
|
|
537
537
|
});
|
|
538
538
|
// 写入 Redis(使用 TTL 时一并写 meta)
|
|
539
539
|
try {
|
|
540
|
-
if (ttl && ttl > 0) {
|
|
540
|
+
if ((ttl && ttl > 0) || ttl === -1) {
|
|
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);
|
|
546
|
-
await Redis.set(`${redisKey}:meta`, meta);
|
|
547
|
-
}
|
|
548
544
|
}
|
|
549
545
|
catch (error) {
|
|
550
546
|
logger.warn('Failed to save cookie to Redis:', redisKey, error);
|