@floating-live/bilibili 0.16.3 → 0.16.5
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/package.json +4 -4
- package/plugin.d.ts +1 -0
- package/plugin.js +19 -6
- package/room.js +2 -4
- package/utils/request.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@floating-live/bilibili",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"check": "tsc --noEmit",
|
|
11
11
|
"clear": "rimraf **/*.js **/*.d.ts --glob",
|
|
12
|
-
"build": "npm run clear && tsc --build && tsc-alias",
|
|
12
|
+
"build": "npm run clear && npm run check && tsc --build && tsc-alias",
|
|
13
13
|
"prepack": "npm run build",
|
|
14
14
|
"postpack": "npm run clear"
|
|
15
15
|
},
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@floating-live/cookies": "^0.1.0",
|
|
21
|
-
"bilibili-live-danmaku": "^0.7.
|
|
21
|
+
"bilibili-live-danmaku": "^0.7.6",
|
|
22
22
|
"md5": "^2.3.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"floating-live": "^0.16.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "597bd2f8bbf24e5895d5f54d26cb9220a93711a3"
|
|
37
37
|
}
|
package/plugin.d.ts
CHANGED
package/plugin.js
CHANGED
|
@@ -57,23 +57,33 @@ export class PluginBilibili extends BasePlugin {
|
|
|
57
57
|
return await fetchLiveRoomData(this.apiClient, parseInt(id.toString()));
|
|
58
58
|
});
|
|
59
59
|
ctx.registerCommand("bilibili.credentials.check", async (e, credentials) => {
|
|
60
|
+
let refreshed = true;
|
|
60
61
|
const apiClient = new BilibiliApiClientEx({
|
|
61
62
|
cookie: credentials,
|
|
62
63
|
userAgent: this.apiClient.userAgent,
|
|
63
64
|
fetch: this.apiClient.fetch,
|
|
64
65
|
});
|
|
66
|
+
// 如buvid3缺失,则初始化cookie
|
|
67
|
+
if (!apiClient.cookies.has("buvid3")) {
|
|
68
|
+
await apiClient.initCookie();
|
|
69
|
+
}
|
|
65
70
|
try {
|
|
66
71
|
// 检测cookie是否需要更新
|
|
67
72
|
const { refresh, timestamp } = (await apiClient.xpassportCookieInfo())
|
|
68
73
|
.data;
|
|
69
74
|
if (refresh) {
|
|
70
75
|
const refresh_token = apiClient.cookies.get("refresh_token");
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
if (refresh_token) {
|
|
77
|
+
// 如果存在refresh_token字段,则刷新cookie,否则将检查结果标记为未刷新
|
|
78
|
+
const { refresh_token: new_refresh_token } = await apiClient.refreshCookie({
|
|
79
|
+
timestamp,
|
|
80
|
+
refresh_token,
|
|
81
|
+
});
|
|
82
|
+
apiClient.cookies.set("refresh_token", new_refresh_token);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
refreshed = false;
|
|
86
|
+
}
|
|
77
87
|
}
|
|
78
88
|
// 检测登录状态
|
|
79
89
|
const data = (await apiClient.xapiNav()).data;
|
|
@@ -85,15 +95,18 @@ export class PluginBilibili extends BasePlugin {
|
|
|
85
95
|
name: data.uname,
|
|
86
96
|
avatar: data.face,
|
|
87
97
|
},
|
|
98
|
+
refreshed,
|
|
88
99
|
};
|
|
89
100
|
}
|
|
90
101
|
catch (e) {
|
|
91
102
|
if (e.ok && e.code == -101) {
|
|
103
|
+
// 用户未登录
|
|
92
104
|
return {
|
|
93
105
|
credentials,
|
|
94
106
|
data: {},
|
|
95
107
|
isLogin: false,
|
|
96
108
|
user: null,
|
|
109
|
+
refreshed,
|
|
97
110
|
};
|
|
98
111
|
}
|
|
99
112
|
else {
|
package/room.js
CHANGED
|
@@ -157,9 +157,9 @@ export class RoomBilibili extends LiveRoom {
|
|
|
157
157
|
/** 设置登录凭据 */
|
|
158
158
|
async setCredentials(credentials, updateTokens = true) {
|
|
159
159
|
__classPrivateFieldGet(this, _RoomBilibili_apiClient, "f").setCookie(credentials);
|
|
160
|
-
// 在没有buvid3
|
|
160
|
+
// 在没有buvid3的情况下,初始化必要cookie
|
|
161
161
|
if (!__classPrivateFieldGet(this, _RoomBilibili_apiClient, "f").cookies.has("buvid3")) {
|
|
162
|
-
__classPrivateFieldGet(this, _RoomBilibili_apiClient, "f").
|
|
162
|
+
await __classPrivateFieldGet(this, _RoomBilibili_apiClient, "f").initCookie();
|
|
163
163
|
}
|
|
164
164
|
if (updateTokens)
|
|
165
165
|
this.updateTokens();
|
|
@@ -242,12 +242,10 @@ export class RoomBilibili extends LiveRoom {
|
|
|
242
242
|
buvid: __classPrivateFieldGet(this, _RoomBilibili_tokens, "f")?.buvid,
|
|
243
243
|
key: __classPrivateFieldGet(this, _RoomBilibili_tokens, "f")?.key,
|
|
244
244
|
});
|
|
245
|
-
console.log(__classPrivateFieldGet(this, _RoomBilibili_tokens, "f"));
|
|
246
245
|
const controller = new AbortController();
|
|
247
246
|
const signal = controller.signal;
|
|
248
247
|
client[symbolAbortController] = controller;
|
|
249
248
|
this.lastConnectionTime = Date.now();
|
|
250
|
-
console.log(client.ws.url);
|
|
251
249
|
client.addEventListener("open", () => {
|
|
252
250
|
// 连接到服务器
|
|
253
251
|
this.opened && this.emitConnention(LiveConnectionStatus.connected);
|
package/utils/request.js
CHANGED
|
@@ -36,7 +36,7 @@ export class BilibiliApiClientEx extends BilibiliApiClient {
|
|
|
36
36
|
url.searchParams.set("refresh_csrf", params.refresh_csrf);
|
|
37
37
|
url.searchParams.set("source", params.source || "main_web");
|
|
38
38
|
url.searchParams.set("refresh_token", params.refresh_token);
|
|
39
|
-
const res = await this.request(url);
|
|
39
|
+
const res = await this.request(url, { method: "POST" });
|
|
40
40
|
const data = unwrapRequestData(res);
|
|
41
41
|
this.cookies.setFromHeaders(res.headers);
|
|
42
42
|
return data;
|
|
@@ -45,7 +45,7 @@ export class BilibiliApiClientEx extends BilibiliApiClient {
|
|
|
45
45
|
const url = new URL("https://passport.bilibili.com/x/passport-login/web/confirm/refresh");
|
|
46
46
|
url.searchParams.set("csrf", params.csrf);
|
|
47
47
|
url.searchParams.set("refresh_token", params.refresh_token);
|
|
48
|
-
const res = await this.request(url);
|
|
48
|
+
const res = await this.request(url, { method: "POST" });
|
|
49
49
|
return unwrapRequestData(res);
|
|
50
50
|
}
|
|
51
51
|
async refreshCookie({ timestamp, refresh_token, }) {
|