yz-yuki-plugin 2.0.9-5 → 2.0.9-6
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
|
@@ -14,7 +14,7 @@ class BilibiliWebDataFetcher {
|
|
|
14
14
|
/**通过uid获取up动态数据表*/
|
|
15
15
|
async getBiliDynamicListDataByUid(uid) {
|
|
16
16
|
const url = BiliApi.BILIBIL_API.biliDynamicInfoList;
|
|
17
|
-
const
|
|
17
|
+
const bili_ticket = await BiliCookieManager.checkCookieBiliTicket();
|
|
18
18
|
const { cookie, mark } = await BiliCookieManager.readSyncCookie();
|
|
19
19
|
const dmImg = await getDmImg();
|
|
20
20
|
const data = {
|
|
@@ -30,8 +30,8 @@ class BilibiliWebDataFetcher {
|
|
|
30
30
|
};
|
|
31
31
|
// 根据 mark 的值计算 signCookie
|
|
32
32
|
const signCookie = mark === 'localCk'
|
|
33
|
-
? (await BiliCookieManager.readSavedCookieItems(`${
|
|
34
|
-
(await BiliCookieManager.readSavedCookieOtherItems(`${
|
|
33
|
+
? (await BiliCookieManager.readSavedCookieItems(`${bili_ticket};${cookie}`, ['SESSDATA'], false)) ||
|
|
34
|
+
(await BiliCookieManager.readSavedCookieOtherItems(`${bili_ticket};${cookie}`, ['SESSDATA']))
|
|
35
35
|
: (await BiliCookieManager.readSavedCookieItems(await BiliCookieManager.getCookieStringForUrl(url), ['SESSDATA'], false)) ||
|
|
36
36
|
(await BiliCookieManager.readSavedCookieOtherItems(await BiliCookieManager.getCookieStringForUrl(url), ['SESSDATA']));
|
|
37
37
|
const { w_rid, time_stamp } = await getWbiSign(data, BiliApi.BILIBILI_HEADERS, signCookie);
|
|
@@ -41,7 +41,7 @@ class BilibiliWebDataFetcher {
|
|
|
41
41
|
wts: time_stamp
|
|
42
42
|
};
|
|
43
43
|
const headers = lodash.merge(BiliApi.BILIBILI_HEADERS, {
|
|
44
|
-
Cookie: mark === 'localCk' ? `${
|
|
44
|
+
Cookie: mark === 'localCk' ? `${bili_ticket};${cookie}` : undefined,
|
|
45
45
|
Host: `api.bilibili.com`,
|
|
46
46
|
Origin: 'https://space.bilibili.com',
|
|
47
47
|
Referer: `https://space.bilibili.com/${uid}/dynamic`
|
|
@@ -96,7 +96,7 @@ class BilibiliWebDataFetcher {
|
|
|
96
96
|
/**通过uid获取up详情*/
|
|
97
97
|
async getBilibiUserInfoByUid(uid) {
|
|
98
98
|
const url = BiliApi.BILIBIL_API.biliSpaceUserInfoWbi;
|
|
99
|
-
const
|
|
99
|
+
const bili_ticket = await BiliCookieManager.checkCookieBiliTicket();
|
|
100
100
|
const { cookie, mark } = await BiliCookieManager.readSyncCookie();
|
|
101
101
|
const dmImg = await getDmImg();
|
|
102
102
|
const data = {
|
|
@@ -108,8 +108,8 @@ class BilibiliWebDataFetcher {
|
|
|
108
108
|
};
|
|
109
109
|
// 根据 mark 的值计算 signCookie
|
|
110
110
|
const signCookie = mark === 'localCk'
|
|
111
|
-
? (await BiliCookieManager.readSavedCookieItems(`${
|
|
112
|
-
(await BiliCookieManager.readSavedCookieOtherItems(`${
|
|
111
|
+
? (await BiliCookieManager.readSavedCookieItems(`${bili_ticket};${cookie}`, ['SESSDATA'], false)) ||
|
|
112
|
+
(await BiliCookieManager.readSavedCookieOtherItems(`${bili_ticket};${cookie}`, ['SESSDATA']))
|
|
113
113
|
: (await BiliCookieManager.readSavedCookieItems(await BiliCookieManager.getCookieStringForUrl(url), ['SESSDATA'], false)) ||
|
|
114
114
|
(await BiliCookieManager.readSavedCookieOtherItems(await BiliCookieManager.getCookieStringForUrl(url), ['SESSDATA']));
|
|
115
115
|
const { w_rid, time_stamp } = await getWbiSign(data, BiliApi.BILIBILI_HEADERS, signCookie);
|
|
@@ -119,7 +119,7 @@ class BilibiliWebDataFetcher {
|
|
|
119
119
|
wts: time_stamp
|
|
120
120
|
};
|
|
121
121
|
const headers = lodash.merge(BiliApi.BILIBILI_HEADERS, {
|
|
122
|
-
Cookie: mark === 'localCk' ? `${
|
|
122
|
+
Cookie: mark === 'localCk' ? `${bili_ticket};${cookie}` : undefined,
|
|
123
123
|
Host: `api.bilibili.com`,
|
|
124
124
|
Origin: 'https://space.bilibili.com',
|
|
125
125
|
Referer: `https://space.bilibili.com/${uid}/dynamic`
|
|
@@ -136,7 +136,7 @@ class BilibiliWebDataFetcher {
|
|
|
136
136
|
/**通过关键词搜索up*/
|
|
137
137
|
async searchBiliUserInfoByKeyword(keyword) {
|
|
138
138
|
const url = BiliApi.BILIBIL_API.biliSearchUpWbi;
|
|
139
|
-
const
|
|
139
|
+
const bili_ticket = await BiliCookieManager.checkCookieBiliTicket();
|
|
140
140
|
const { cookie, mark } = await BiliCookieManager.readSyncCookie();
|
|
141
141
|
const data = {
|
|
142
142
|
keyword: keyword,
|
|
@@ -146,8 +146,8 @@ class BilibiliWebDataFetcher {
|
|
|
146
146
|
};
|
|
147
147
|
// 根据 mark 的值计算 signCookie
|
|
148
148
|
const signCookie = mark === 'localCk'
|
|
149
|
-
? (await BiliCookieManager.readSavedCookieItems(`${
|
|
150
|
-
(await BiliCookieManager.readSavedCookieOtherItems(`${
|
|
149
|
+
? (await BiliCookieManager.readSavedCookieItems(`${bili_ticket};${cookie}`, ['SESSDATA'], false)) ||
|
|
150
|
+
(await BiliCookieManager.readSavedCookieOtherItems(`${bili_ticket};${cookie}`, ['SESSDATA']))
|
|
151
151
|
: (await BiliCookieManager.readSavedCookieItems(await BiliCookieManager.getCookieStringForUrl(url), ['SESSDATA'], false)) ||
|
|
152
152
|
(await BiliCookieManager.readSavedCookieOtherItems(await BiliCookieManager.getCookieStringForUrl(url), ['SESSDATA']));
|
|
153
153
|
const { w_rid, time_stamp } = await getWbiSign(data, BiliApi.BILIBILI_HEADERS, signCookie);
|
|
@@ -157,7 +157,7 @@ class BilibiliWebDataFetcher {
|
|
|
157
157
|
wts: time_stamp
|
|
158
158
|
};
|
|
159
159
|
const headers = lodash.merge(BiliApi.BILIBILI_HEADERS, {
|
|
160
|
-
Cookie: mark === 'localCk' ? `${
|
|
160
|
+
Cookie: mark === 'localCk' ? `${bili_ticket};${cookie}` : undefined,
|
|
161
161
|
Host: `api.bilibili.com`,
|
|
162
162
|
Origin: 'https://www.bilibili.com',
|
|
163
163
|
Referer: `https://www.bilibili.com/`
|
|
@@ -174,14 +174,14 @@ class BilibiliWebDataFetcher {
|
|
|
174
174
|
/*通过aid/bvid获取视频信息*/
|
|
175
175
|
async getBiliVideoInfoByAid_BV(vedioID) {
|
|
176
176
|
const url = BiliApi.BILIBIL_API.biliVideoInfoWbi;
|
|
177
|
-
const
|
|
177
|
+
const bili_ticket = await BiliCookieManager.checkCookieBiliTicket();
|
|
178
178
|
const { cookie, mark } = await BiliCookieManager.readSyncCookie();
|
|
179
179
|
let referer = vedioID?.bvid ? `https://www.bilibili.com/video/${vedioID.bvid}` : `https://www.bilibili.com/video/av${vedioID.aid}`;
|
|
180
180
|
let data = vedioID?.bvid ? { bvid: vedioID.bvid } : { aid: vedioID.aid };
|
|
181
181
|
// 根据 mark 的值计算 signCookie
|
|
182
182
|
const signCookie = mark === 'localCk'
|
|
183
|
-
? (await BiliCookieManager.readSavedCookieItems(`${
|
|
184
|
-
(await BiliCookieManager.readSavedCookieOtherItems(`${
|
|
183
|
+
? (await BiliCookieManager.readSavedCookieItems(`${bili_ticket};${cookie}`, ['SESSDATA'], false)) ||
|
|
184
|
+
(await BiliCookieManager.readSavedCookieOtherItems(`${bili_ticket};${cookie}`, ['SESSDATA']))
|
|
185
185
|
: (await BiliCookieManager.readSavedCookieItems(await BiliCookieManager.getCookieStringForUrl(url), ['SESSDATA'], false)) ||
|
|
186
186
|
(await BiliCookieManager.readSavedCookieOtherItems(await BiliCookieManager.getCookieStringForUrl(url), ['SESSDATA']));
|
|
187
187
|
const { w_rid, time_stamp } = await getWbiSign(data, BiliApi.BILIBILI_HEADERS, signCookie);
|
|
@@ -191,7 +191,7 @@ class BilibiliWebDataFetcher {
|
|
|
191
191
|
wts: time_stamp
|
|
192
192
|
};
|
|
193
193
|
const headers = lodash.merge(BiliApi.BILIBILI_HEADERS, {
|
|
194
|
-
Cookie: mark === 'localCk' ? `${
|
|
194
|
+
Cookie: mark === 'localCk' ? `${bili_ticket};${cookie}` : undefined,
|
|
195
195
|
Host: `api.bilibili.com`,
|
|
196
196
|
Origin: 'https://www.bilibili.com',
|
|
197
197
|
Referer: referer
|
|
@@ -209,10 +209,10 @@ class BilibiliWebDataFetcher {
|
|
|
209
209
|
async getBVIDByShortUrl(tvUrlID) {
|
|
210
210
|
const ShortVideoUrlApi = BiliApi.BILIBIL_API.biliShortVideoUrl;
|
|
211
211
|
const url = `${ShortVideoUrlApi}${tvUrlID}`;
|
|
212
|
-
const
|
|
212
|
+
const bili_ticket = await BiliCookieManager.checkCookieBiliTicket();
|
|
213
213
|
const { cookie, mark } = await BiliCookieManager.readSyncCookie();
|
|
214
214
|
const headers = lodash.merge(BiliApi.BILIBILI_DYNAMIC_SPACE_HEADERS, {
|
|
215
|
-
Cookie: mark === 'localCk' ? `${
|
|
215
|
+
Cookie: mark === 'localCk' ? `${bili_ticket};${cookie}` : undefined
|
|
216
216
|
});
|
|
217
217
|
const ck = cookie instanceof tough.CookieJar ? cookie : undefined;
|
|
218
218
|
const res = await axios.get(url, {
|
|
@@ -247,11 +247,11 @@ class BiliQuery {
|
|
|
247
247
|
* @returns 完整的B站文章内容json数据
|
|
248
248
|
*/
|
|
249
249
|
static async getFullArticleContent(postUrl) {
|
|
250
|
-
const
|
|
250
|
+
const bili_ticket = await BiliCookieManager.checkCookieBiliTicket();
|
|
251
251
|
const { cookie, mark } = await BiliCookieManager.readSyncCookie();
|
|
252
252
|
try {
|
|
253
253
|
const headers = lodash.merge(BiliApi.BILIBILI_ARTICLE_HEADERS, {
|
|
254
|
-
Cookie: mark === 'localCk' ? `${
|
|
254
|
+
Cookie: mark === 'localCk' ? `${bili_ticket};${cookie}` : undefined,
|
|
255
255
|
Host: 'www.bilibili.com'
|
|
256
256
|
});
|
|
257
257
|
const ck = cookie instanceof tough.CookieJar ? cookie : undefined;
|
|
@@ -197,7 +197,8 @@ class BiliRiskCookie {
|
|
|
197
197
|
resolve(cookieString || '');
|
|
198
198
|
});
|
|
199
199
|
});
|
|
200
|
-
const
|
|
200
|
+
const bili_ticket = await this.checkCookieBiliTicket(true);
|
|
201
|
+
const result = await this.postGateway(cookieString + ';' + bili_ticket); //激活ck
|
|
201
202
|
const { code, data } = await result.data; // 解析校验结果
|
|
202
203
|
switch (code) {
|
|
203
204
|
case 0:
|
|
@@ -349,7 +350,7 @@ class BiliRiskCookie {
|
|
|
349
350
|
headers: {
|
|
350
351
|
'Host': 'passport.bilibili.com',
|
|
351
352
|
'User-Agent': BiliApi.BILIBILI_HEADERS['User-Agent'],
|
|
352
|
-
'Cookie': `DedeUserID
|
|
353
|
+
'Cookie': `DedeUserID=${DedeUserID};bili_jct=${biliCSRF};SESSDATA=${SESSDATA}`,
|
|
353
354
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
354
355
|
}
|
|
355
356
|
});
|
|
@@ -385,19 +386,20 @@ class BiliRiskCookie {
|
|
|
385
386
|
/**
|
|
386
387
|
* 获取有效bili_ticket并添加到cookie(bili_ticket 仍缓存于 Redis 单独 key)
|
|
387
388
|
*/
|
|
388
|
-
async checkCookieBiliTicket() {
|
|
389
|
-
const
|
|
390
|
-
if (
|
|
389
|
+
async checkCookieBiliTicket(forseRefresh = false) {
|
|
390
|
+
const bili_ticket_expires = await this.getCookieExpiration(this.cookieJar, 'bili_ticket', 'https://api.bilibili.com');
|
|
391
|
+
if (bili_ticket_expires === null || forseRefresh) {
|
|
391
392
|
try {
|
|
392
|
-
const
|
|
393
|
+
const bili_jct = await this.getCookieValueByKeyFromString(this.cookieJar, 'bili_jct', 'https://api.bilibili.com');
|
|
394
|
+
const { ticket, ttl } = await getBiliTicket(bili_jct ? bili_jct : '');
|
|
393
395
|
if (ticket && ttl) {
|
|
394
396
|
await this.setCookieString([
|
|
395
397
|
new tough.Cookie({
|
|
396
|
-
key: '
|
|
398
|
+
key: 'bili_ticket',
|
|
397
399
|
value: ticket,
|
|
398
400
|
domain: '.bilibili.com',
|
|
399
401
|
path: '/',
|
|
400
|
-
expires: new Date(Date.now() + ttl) // 3天后过期
|
|
402
|
+
expires: new Date(Date.now() + ttl * 1000) // 3天后过期
|
|
401
403
|
})
|
|
402
404
|
]);
|
|
403
405
|
return `bili_ticket=${ticket};`;
|
|
@@ -411,7 +413,7 @@ class BiliRiskCookie {
|
|
|
411
413
|
}
|
|
412
414
|
}
|
|
413
415
|
else {
|
|
414
|
-
return `
|
|
416
|
+
return `bili_ticket=${await this.getCookieValueByKeyFromString(this.cookieJar, 'bili_ticket', 'https://api.bilibili.com')};`;
|
|
415
417
|
}
|
|
416
418
|
}
|
|
417
419
|
/**
|
|
@@ -473,7 +475,7 @@ class BiliRiskCookie {
|
|
|
473
475
|
}
|
|
474
476
|
}
|
|
475
477
|
/**
|
|
476
|
-
* 简单策略:优先从 Redis 读取长期 cookie(如
|
|
478
|
+
* 简单策略:优先从 Redis 读取长期 cookie(如 SESSDATA),若缺失则触发完整获取流程
|
|
477
479
|
* */
|
|
478
480
|
async ensureLoginCookies(jar) {
|
|
479
481
|
// 常见域名为 .weibo.cn 或 m.weibo.cn,根据实际情况检查
|
|
@@ -481,7 +483,7 @@ class BiliRiskCookie {
|
|
|
481
483
|
const SESSDATA_Key2 = `${this.prefix}:bilibili.com:SESSDATA`;
|
|
482
484
|
const isLogin = (await Redis.get(SESSDATA_Key1)) || (await Redis.get(SESSDATA_Key2));
|
|
483
485
|
if (isLogin) {
|
|
484
|
-
// 直接把 Redis 的所有 cookie 恢复到 jar(包含
|
|
486
|
+
// 直接把 Redis 的所有 cookie 恢复到 jar(包含 SESSDATA)
|
|
485
487
|
await this.loadCookiesFromRedis(jar);
|
|
486
488
|
return true;
|
|
487
489
|
}
|
|
@@ -35,12 +35,12 @@ async function getBiliTicket(csrf) {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
if (!response.ok) {
|
|
38
|
-
throw new Error(`get
|
|
38
|
+
throw new Error(`get bili_ticket HTTP error! status: ${response.status}`);
|
|
39
39
|
}
|
|
40
|
-
const data = await response.json();
|
|
40
|
+
const data = (await response.json());
|
|
41
41
|
if (data.code !== 0) {
|
|
42
42
|
if (data.code === 400) {
|
|
43
|
-
throw new Error(`get
|
|
43
|
+
throw new Error(`get bili_ticket Parameter error! ${data.message}`);
|
|
44
44
|
}
|
|
45
45
|
throw new Error(`Failed to retrieve bili ticket: ${data.message}`);
|
|
46
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yz-yuki-plugin",
|
|
3
|
-
"version": "2.0.9-
|
|
3
|
+
"version": "2.0.9-6",
|
|
4
4
|
"description": "优纪插件,yunzaijs 关于 微博推送、B站推送 等功能的拓展插件",
|
|
5
5
|
"author": "snowtafir",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"private": false,
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/snowtafir/yuki-plugin.git"
|
|
11
|
+
"url": "git+https://github.com/snowtafir/yuki-plugin.git"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
14
|
"app": "node lib/main.js",
|