@floating-live/bilibili 0.16.4 → 0.16.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floating-live/bilibili",
3
- "version": "0.16.4",
3
+ "version": "0.16.6",
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.4",
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": "d77963e0a011c84f6ed667a2e53f7b89cbd5400a"
36
+ "gitHead": "2213763b645f5cdf3af7cb322498af995724e2d1"
37
37
  }
package/plugin.d.ts CHANGED
@@ -4,6 +4,7 @@ interface BilibiliLoginInfo {
4
4
  credentials: string;
5
5
  isLogin: boolean;
6
6
  user: UserInfo | null;
7
+ refreshed: boolean;
7
8
  }
8
9
  declare module "floating-live" {
9
10
  interface AppCommandMap {
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
- // 更新cookie
72
- const { refresh_token: new_refresh_token } = await apiClient.refreshCookie({
73
- timestamp,
74
- refresh_token,
75
- });
76
- apiClient.cookies.set("refresh_token", new_refresh_token);
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的情况下,访问bilibili主页,获得buvid3
160
+ // 在没有buvid3的情况下,初始化必要cookie
161
161
  if (!__classPrivateFieldGet(this, _RoomBilibili_apiClient, "f").cookies.has("buvid3")) {
162
- __classPrivateFieldGet(this, _RoomBilibili_apiClient, "f").wwwBilibili();
162
+ await __classPrivateFieldGet(this, _RoomBilibili_apiClient, "f").initCookie();
163
163
  }
164
164
  if (updateTokens)
165
165
  this.updateTokens();
package/utils/request.js CHANGED
@@ -11,7 +11,7 @@ export class BilibiliApiClientEx extends BilibiliApiClient {
11
11
  async xpassportQrcodePoll(params) {
12
12
  const url = new URL("https://passport.bilibili.com/x/passport-login/web/qrcode/poll");
13
13
  url.searchParams.set("qrcode_key", params.qrcode_key);
14
- const res = await this.request("https://passport.bilibili.com/x/passport-login/web/qrcode/generate");
14
+ const res = await this.request(url);
15
15
  const data = unwrapRequestData(res);
16
16
  this.cookies.setFromHeaders(res.headers);
17
17
  return data;
@@ -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, }) {