floating-live 0.14.6 → 0.14.8

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",
3
- "version": "0.14.6",
3
+ "version": "0.14.8",
4
4
  "type": "commonjs",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  const room_1 = __importDefault(require("./room"));
6
+ const utils_1 = require("./utils");
6
7
  const bilibili = () => {
7
8
  return {
8
9
  name: "bilibili",
@@ -11,18 +12,34 @@ const bilibili = () => {
11
12
  return new room_1.default(Number(id), open, config);
12
13
  });
13
14
  ctx.auth.options.register("bilibili", authConfig);
15
+ ctx.command.register("auth.bilibili", async (auth) => {
16
+ const uid = await (0, utils_1.getLoginUid)(auth);
17
+ ctx.auth.status["bilibili"] = uid;
18
+ ctx.auth.set("bilibili", auth);
19
+ ctx.emit("auth:update", "bilibili", uid);
20
+ });
21
+ ctx.command.register("auth.bilibili.qrcode.get", () => {
22
+ return (0, utils_1.generateLoginQRcode)();
23
+ });
24
+ ctx.command.register("auth.bilibili.qrcode.check", async (key) => {
25
+ const [code, auth] = await (0, utils_1.checkLoginQRcode)(key);
26
+ if (auth) {
27
+ const { SESSDATA, DedeUserID } = (0, utils_1.parseCookieString)(auth);
28
+ ctx.auth.status["bilibili"] = DedeUserID;
29
+ ctx.auth.set("bilibili", `SESSDATA=${SESSDATA}`);
30
+ ctx.emit("auth:update", "bilibili", DedeUserID);
31
+ }
32
+ return code;
33
+ });
14
34
  },
15
35
  };
16
36
  };
17
37
  const authConfig = {
18
- info: "由于b站弹幕接口限制,在未登录账号的情况下,返回的弹幕用户名会变为星号且无法获取到uid。\n详见(github:simon300000/bilibili-live-ws#397)[https://github.com/simon300000/bilibili-live-ws/issues/397]",
19
38
  auth: {
20
- placeholder: "此处粘贴cookie",
21
- info: "请在登录后的b站页面中获取cookie并粘贴在输入框内,至少包含SESSDATA字段。",
39
+ type: "cookie",
22
40
  },
23
41
  qrcode: {
24
- // generate: () => {},
42
+ type: "url",
25
43
  },
26
- // verify: { name: "key", type: "string" },
27
44
  };
28
45
  module.exports = bilibili;
@@ -13,4 +13,4 @@ export declare function generateLoginQRcode(): Promise<{
13
13
  /** 在终端打印登录二维码 */
14
14
  export declare function printQRcode(url: string): void;
15
15
  /** 检测登录二维码 */
16
- export declare function checkLoginQRcode(key: string): Promise<unknown>;
16
+ export declare function checkLoginQRcode(key: string): Promise<(string | number | null)[]>;
@@ -92,49 +92,34 @@ function printQRcode(url) {
92
92
  }
93
93
  exports.printQRcode = printQRcode;
94
94
  /** 检测登录二维码 */
95
- function checkLoginQRcode(key) {
96
- return new Promise((resolve, reject) => {
97
- let timer = 0;
98
- const pollFuction = async () => {
99
- clearTimeout(timer);
100
- const res = await fetch(`https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=${key}`, {
101
- headers: {
102
- "User-Agent": USER_AGENT,
103
- },
104
- });
105
- const { code, message } = (await res.json()).data;
106
- if (code == 86101) {
107
- console.log("未扫码");
108
- timer = setTimeout(pollFuction, 1000);
109
- }
110
- else if (code == 86090) {
111
- console.log("等待确认");
112
- timer = setTimeout(pollFuction, 1000);
113
- }
114
- else if (code == 0) {
115
- console.log("登录成功");
116
- const a = res.headers.get("set-cookie");
117
- resolve(a);
118
- }
119
- else if (code == 86038) {
120
- console.log("二维码失效");
121
- resolve("");
122
- }
123
- else {
124
- console.log(`${code} ${message}`);
125
- resolve("");
126
- }
127
- };
128
- timer = setTimeout(pollFuction, 1000);
129
- });
130
- }
131
- exports.checkLoginQRcode = checkLoginQRcode;
132
- /** 轮询登录二维码 */
133
- async function pollLoginQRCode(key) {
95
+ async function checkLoginQRcode(key) {
134
96
  const res = await fetch(`https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=${key}`, {
135
97
  headers: {
136
98
  "User-Agent": USER_AGENT,
137
99
  },
138
100
  });
139
- return;
101
+ const { code, message } = (await res.json()).data;
102
+ if (code == 86101) {
103
+ // 未扫码
104
+ return [1];
105
+ }
106
+ else if (code == 86090) {
107
+ // 等待确认
108
+ return [2];
109
+ }
110
+ else if (code == 0) {
111
+ // 登录成功
112
+ const cookie = res.headers.get("set-cookie");
113
+ return [0, cookie];
114
+ }
115
+ else if (code == 86038) {
116
+ // 二维码失效
117
+ return [-1];
118
+ }
119
+ else {
120
+ // 其他错误
121
+ console.log(`${code} ${message}`);
122
+ throw message;
123
+ }
140
124
  }
125
+ exports.checkLoginQRcode = checkLoginQRcode;
@@ -16,6 +16,8 @@ export declare class Reglist<T> {
16
16
  getName(): string;
17
17
  /** 根据id获取注册对象 */
18
18
  get(id: string): T | undefined;
19
+ /** 检查注册对象是否存在 */
20
+ has(id: string): boolean;
19
21
  /** 获取注册对象列表 */
20
22
  getList(): T[];
21
23
  /** 遍历 */
@@ -45,6 +45,10 @@ class Reglist {
45
45
  get(id) {
46
46
  return this.list.get(id);
47
47
  }
48
+ /** 检查注册对象是否存在 */
49
+ has(id) {
50
+ return this.list.has(id);
51
+ }
48
52
  /** 获取注册对象列表 */
49
53
  getList() {
50
54
  return [...this.list.values()];
@@ -1,7 +1,9 @@
1
1
  import { Reglist } from "../abstract/Reglist";
2
2
  import { FloatingLive } from "..";
3
+ import { AuthOptions } from "../types/auth";
3
4
  export declare class ModAuth {
4
- options: Reglist<object>;
5
+ options: Reglist<AuthOptions>;
6
+ status: Record<string, string | number>;
5
7
  main: FloatingLive;
6
8
  constructor(main: FloatingLive);
7
9
  set(name: string, auth: string): void;
@@ -4,6 +4,7 @@ exports.ModAuth = void 0;
4
4
  const Reglist_1 = require("../abstract/Reglist");
5
5
  class ModAuth {
6
6
  constructor(main) {
7
+ this.status = {};
7
8
  this.options = new Reglist_1.Reglist(main, "auth.options");
8
9
  this.main = main;
9
10
  this.main.state.register("auth", () => {
@@ -13,11 +14,17 @@ class ModAuth {
13
14
  });
14
15
  return {
15
16
  options: options,
17
+ status: this.status,
16
18
  };
17
19
  });
18
20
  this.main.command.batchRegister({
19
21
  auth: (platform, auth) => {
20
- this.set(platform, auth);
22
+ if (this.main.command.has(`auth.${platform}`)) {
23
+ this.main.command.execute(`auth.${platform}`, auth);
24
+ }
25
+ else {
26
+ this.set(platform, auth);
27
+ }
21
28
  },
22
29
  });
23
30
  }
@@ -0,0 +1,19 @@
1
+ export interface AuthOptions {
2
+ /** 直接输入凭证 */
3
+ auth: {
4
+ /** 凭证类型 */
5
+ type: string;
6
+ };
7
+ /** 二维码登录 */
8
+ qrcode?: {
9
+ /** 二维码类型 */
10
+ type: "url" | "base64";
11
+ };
12
+ /** 验证码登录 */
13
+ verify?: {
14
+ /** 验证码发送等待间隔(秒) */
15
+ wait: number;
16
+ /** 第三方验证接口 */
17
+ captcha?: string;
18
+ };
19
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,4 @@
1
1
  export * from "./message";
2
2
  export * from "./plugin";
3
3
  export * from "./room";
4
+ export * from "./auth";
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./message"), exports);
18
18
  __exportStar(require("./plugin"), exports);
19
19
  __exportStar(require("./room"), exports);
20
+ __exportStar(require("./auth"), exports);
@@ -27,16 +27,16 @@ export interface RoomInfo {
27
27
  connected: boolean;
28
28
  }
29
29
  /** 房间展示信息 */
30
- export declare type RoomDetail = {
30
+ export interface RoomDetail {
31
31
  /** 直播标题 */
32
32
  title?: string;
33
33
  /** 分区 */
34
34
  area?: string[];
35
35
  /** 封面 */
36
36
  cover?: string;
37
- };
37
+ }
38
38
  /** 房间统计数据信息 */
39
- export declare type RoomStatsInfo = {
39
+ export interface RoomStatsInfo {
40
40
  /** 点赞数 */
41
41
  like?: number;
42
42
  /** 观看数 */
@@ -45,7 +45,7 @@ export declare type RoomStatsInfo = {
45
45
  online?: number;
46
46
  /** 人气值 */
47
47
  popularity?: number;
48
- };
48
+ }
49
49
  export interface PlatformInfo {
50
50
  /** 平台名称 */
51
51
  name: string;
@@ -67,20 +67,19 @@ export interface PlatformInfo {
67
67
  /** 粉丝vip名称 */
68
68
  name: string;
69
69
  /** 粉丝vip等级名称 */
70
- level?: string;
70
+ level?: string[];
71
71
  };
72
72
  /** 礼物信息 */
73
73
  gift: {
74
- /** 货币 */
75
- currency: Array<{
76
- /** 货币id */
77
- id: string;
78
- /** 货币名称 */
79
- name: string;
80
- /** 1货币面值等值value (1面值/1数值) */
81
- face: number;
82
- /** 1人民币等值value (1.00CNY/1数值) (若为0则为免费货币) */
83
- cny?: number;
84
- }>;
74
+ action: string;
85
75
  };
76
+ /** 货币信息 */
77
+ currency: Record<string, {
78
+ /** 货币名称 */
79
+ name: string;
80
+ /** 1货币面值等值value (1面值/1数值) */
81
+ face: number;
82
+ /** 1人民币等值value (1.00CNY/1数值) (若为0则为免费货币) */
83
+ cny?: number;
84
+ }>;
86
85
  }