koishi-plugin-bilibili-notify 3.2.5-alpha.1 → 3.2.5-alpha.10
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/lib/index.js +94897 -28
- package/lib/index.mjs +94893 -21
- package/package.json +6 -6
- package/readme.md +9 -0
- package/lib/assets/HYZhengYuan-75W-CAgMN3FH.ttf +0 -0
- package/lib/biliAPI-BB6Ih4EM.mjs +0 -659
- package/lib/biliAPI-GF2e2-2V.js +0 -664
- package/lib/biliAPI.d.mts +0 -82
- package/lib/biliAPI.d.ts +0 -82
- package/lib/biliAPI.js +0 -5
- package/lib/biliAPI.mjs +0 -4
- package/lib/blive-BBVUYbxX.js +0 -43
- package/lib/blive-CyC_0-9A.mjs +0 -37
- package/lib/blive.d.mts +0 -19
- package/lib/blive.d.ts +0 -19
- package/lib/blive.js +0 -4
- package/lib/blive.mjs +0 -3
- package/lib/chunk-CrFLpmCJ.js +0 -67
- package/lib/chunk-DBmNgn_A.mjs +0 -40
- package/lib/comRegister-CcqOpkwB.mjs +0 -1421
- package/lib/comRegister-t7UnYFig.js +0 -1426
- package/lib/comRegister.d.mts +0 -109
- package/lib/comRegister.d.ts +0 -109
- package/lib/comRegister.js +0 -6
- package/lib/comRegister.mjs +0 -5
- package/lib/database-4f9U--Ji.mjs +0 -20
- package/lib/database-Ct2yIdxk.js +0 -37
- package/lib/database-Do3O9MDA.d.mts +0 -18
- package/lib/database-KWDs372o.d.ts +0 -18
- package/lib/database.d.mts +0 -2
- package/lib/database.d.ts +0 -2
- package/lib/database.js +0 -5
- package/lib/database.mjs +0 -3
- package/lib/font/HYZhengYuan-75W.js +0 -5
- package/lib/font/HYZhengYuan-75W.mjs +0 -5
- package/lib/generateImg-E9JeFpQX.js +0 -92628
- package/lib/generateImg-zwzMYjw6.mjs +0 -92623
- package/lib/generateImg.d.mts +0 -65
- package/lib/generateImg.d.ts +0 -65
- package/lib/generateImg.js +0 -5
- package/lib/generateImg.mjs +0 -4
- package/lib/img/arrow.js +0 -5
- package/lib/img/arrow.mjs +0 -5
- package/lib/index-DeGUe4jM.d.mts +0 -265
- package/lib/index-MJKYbMf7.d.ts +0 -265
- package/lib/page/0.mjs +0 -0
- package/lib/type/index.d.mts +0 -2
- package/lib/type/index.d.ts +0 -2
- package/lib/type/index.js +0 -5
- package/lib/type/index.mjs +0 -3
- package/lib/type-C5ZxPrgY.mjs +0 -19
- package/lib/type-WjCy4YMc.js +0 -31
- package/lib/utils/index.d.mts +0 -15
- package/lib/utils/index.d.ts +0 -15
- package/lib/utils/index.js +0 -6
- package/lib/utils/index.mjs +0 -3
- package/lib/utils-BoaYrSvG.js +0 -79
- package/lib/utils-C95cnBJG.mjs +0 -61
- /package/lib/page/{0.js → 0.html} +0 -0
package/lib/biliAPI-GF2e2-2V.js
DELETED
|
@@ -1,664 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CrFLpmCJ.js');
|
|
2
|
-
const require_utils = require('./utils-BoaYrSvG.js');
|
|
3
|
-
const koishi = require_chunk.__toESM(require("koishi"));
|
|
4
|
-
const md5 = require_chunk.__toESM(require("md5"));
|
|
5
|
-
const node_crypto = require_chunk.__toESM(require("node:crypto"));
|
|
6
|
-
const node_http = require_chunk.__toESM(require("node:http"));
|
|
7
|
-
const node_https = require_chunk.__toESM(require("node:https"));
|
|
8
|
-
const axios = require_chunk.__toESM(require("axios"));
|
|
9
|
-
const tough_cookie = require_chunk.__toESM(require("tough-cookie"));
|
|
10
|
-
const axios_cookiejar_support = require_chunk.__toESM(require("axios-cookiejar-support"));
|
|
11
|
-
const jsdom = require_chunk.__toESM(require("jsdom"));
|
|
12
|
-
|
|
13
|
-
//#region node_modules/@oxc-project/runtime/src/helpers/decorate.js
|
|
14
|
-
var require_decorate = require_chunk.__commonJS({ "node_modules/@oxc-project/runtime/src/helpers/decorate.js"(exports, module) {
|
|
15
|
-
function __decorate(decorators, target, key, desc) {
|
|
16
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
17
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
18
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
19
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
20
|
-
}
|
|
21
|
-
module.exports = __decorate, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
22
|
-
} });
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/biliAPI.ts
|
|
26
|
-
var import_decorate = require_chunk.__toESM(require_decorate());
|
|
27
|
-
const mixinKeyEncTab = [
|
|
28
|
-
46,
|
|
29
|
-
47,
|
|
30
|
-
18,
|
|
31
|
-
2,
|
|
32
|
-
53,
|
|
33
|
-
8,
|
|
34
|
-
23,
|
|
35
|
-
32,
|
|
36
|
-
15,
|
|
37
|
-
50,
|
|
38
|
-
10,
|
|
39
|
-
31,
|
|
40
|
-
58,
|
|
41
|
-
3,
|
|
42
|
-
45,
|
|
43
|
-
35,
|
|
44
|
-
27,
|
|
45
|
-
43,
|
|
46
|
-
5,
|
|
47
|
-
49,
|
|
48
|
-
33,
|
|
49
|
-
9,
|
|
50
|
-
42,
|
|
51
|
-
19,
|
|
52
|
-
29,
|
|
53
|
-
28,
|
|
54
|
-
14,
|
|
55
|
-
39,
|
|
56
|
-
12,
|
|
57
|
-
38,
|
|
58
|
-
41,
|
|
59
|
-
13,
|
|
60
|
-
37,
|
|
61
|
-
48,
|
|
62
|
-
7,
|
|
63
|
-
16,
|
|
64
|
-
24,
|
|
65
|
-
55,
|
|
66
|
-
40,
|
|
67
|
-
61,
|
|
68
|
-
26,
|
|
69
|
-
17,
|
|
70
|
-
0,
|
|
71
|
-
1,
|
|
72
|
-
60,
|
|
73
|
-
51,
|
|
74
|
-
30,
|
|
75
|
-
4,
|
|
76
|
-
22,
|
|
77
|
-
25,
|
|
78
|
-
54,
|
|
79
|
-
21,
|
|
80
|
-
56,
|
|
81
|
-
59,
|
|
82
|
-
6,
|
|
83
|
-
63,
|
|
84
|
-
57,
|
|
85
|
-
62,
|
|
86
|
-
11,
|
|
87
|
-
36,
|
|
88
|
-
20,
|
|
89
|
-
34,
|
|
90
|
-
44,
|
|
91
|
-
52
|
|
92
|
-
];
|
|
93
|
-
const bangumiTripData = {
|
|
94
|
-
code: 0,
|
|
95
|
-
data: { live_room: { roomid: 931774 } }
|
|
96
|
-
};
|
|
97
|
-
const GET_USER_SPACE_DYNAMIC_LIST = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space?platform=web&features=itemOpusStyle";
|
|
98
|
-
const GET_ALL_DYNAMIC_LIST = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?platform=web&features=itemOpusStyle";
|
|
99
|
-
const HAS_NEW_DYNAMIC = "https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all/update";
|
|
100
|
-
const GET_COOKIES_INFO = "https://passport.bilibili.com/x/passport-login/web/cookie/info";
|
|
101
|
-
const GET_USER_INFO = "https://api.bilibili.com/x/space/wbi/acc/info";
|
|
102
|
-
const GET_MYSELF_INFO = "https://api.bilibili.com/x/member/web/account";
|
|
103
|
-
const GET_LOGIN_QRCODE = "https://passport.bilibili.com/x/passport-login/web/qrcode/generate";
|
|
104
|
-
const GET_LOGIN_STATUS = "https://passport.bilibili.com/x/passport-login/web/qrcode/poll";
|
|
105
|
-
const GET_LIVE_ROOM_INFO = "https://api.live.bilibili.com/room/v1/Room/get_info";
|
|
106
|
-
const GET_MASTER_INFO = "https://api.live.bilibili.com/live_user/v1/Master/info";
|
|
107
|
-
const GET_TIME_NOW = "https://api.bilibili.com/x/report/click/now";
|
|
108
|
-
const GET_SERVER_UTC_TIME = "https://interface.bilibili.com/serverdate.js";
|
|
109
|
-
const GET_LATEST_UPDATED_UPS = "https://api.bilibili.com/x/polymer/web-dynamic/v1/portal";
|
|
110
|
-
const MODIFY_RELATION = "https://api.bilibili.com/x/relation/modify";
|
|
111
|
-
const CREATE_GROUP = "https://api.bilibili.com/x/relation/tag/create";
|
|
112
|
-
const MODIFY_GROUP_MEMBER = "https://api.bilibili.com/x/relation/tags/addUsers";
|
|
113
|
-
const GET_ALL_GROUP = "https://api.bilibili.com/x/relation/tags";
|
|
114
|
-
const COPY_USER_TO_GROUP = "https://api.bilibili.com/x/relation/tags/copyUsers";
|
|
115
|
-
const GET_RELATION_GROUP_DETAIL = "https://api.bilibili.com/x/relation/tag";
|
|
116
|
-
const GET_LIVE_ROOM_INFO_STREAM_KEY = "https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo";
|
|
117
|
-
const GET_LIVE_ROOMS_INFO = "https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids";
|
|
118
|
-
var BiliAPI = class extends koishi.Service {
|
|
119
|
-
static inject = ["database", "notifier"];
|
|
120
|
-
jar;
|
|
121
|
-
client;
|
|
122
|
-
apiConfig;
|
|
123
|
-
cacheable;
|
|
124
|
-
loginData;
|
|
125
|
-
loginNotifier;
|
|
126
|
-
refreshCookieTimer;
|
|
127
|
-
loginInfoIsLoaded = false;
|
|
128
|
-
constructor(ctx, config) {
|
|
129
|
-
super(ctx, "ba");
|
|
130
|
-
this.apiConfig = config;
|
|
131
|
-
}
|
|
132
|
-
async start() {
|
|
133
|
-
const CacheableLookup = (await import("cacheable-lookup")).default;
|
|
134
|
-
this.cacheable = new CacheableLookup();
|
|
135
|
-
this.cacheable.install(node_http.default.globalAgent);
|
|
136
|
-
this.cacheable.install(node_https.default.globalAgent);
|
|
137
|
-
this.createNewClient();
|
|
138
|
-
this.loadCookiesFromDatabase();
|
|
139
|
-
}
|
|
140
|
-
stop() {
|
|
141
|
-
this.cacheable.uninstall(node_http.default.globalAgent);
|
|
142
|
-
this.cacheable.uninstall(node_https.default.globalAgent);
|
|
143
|
-
}
|
|
144
|
-
getMixinKey = (orig) => mixinKeyEncTab.map((n) => orig[n]).join("").slice(0, 32);
|
|
145
|
-
encWbi(params, img_key, sub_key) {
|
|
146
|
-
const mixin_key = this.getMixinKey(img_key + sub_key);
|
|
147
|
-
const curr_time = Math.round(Date.now() / 1e3);
|
|
148
|
-
const chr_filter = /[!'()*]/g;
|
|
149
|
-
Object.assign(params, { wts: curr_time });
|
|
150
|
-
const query = Object.keys(params).sort().map((key) => {
|
|
151
|
-
const value = params[key].toString().replace(chr_filter, "");
|
|
152
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
153
|
-
}).join("&");
|
|
154
|
-
const wbi_sign = (0, md5.default)(query + mixin_key);
|
|
155
|
-
return `${query}&w_rid=${wbi_sign}`;
|
|
156
|
-
}
|
|
157
|
-
async getWbi(params) {
|
|
158
|
-
const web_keys = await this.getWbiKeys();
|
|
159
|
-
const img_key = web_keys.img_key;
|
|
160
|
-
const sub_key = web_keys.sub_key;
|
|
161
|
-
const query = this.encWbi(params, img_key, sub_key);
|
|
162
|
-
return query;
|
|
163
|
-
}
|
|
164
|
-
encrypt(text) {
|
|
165
|
-
const iv = node_crypto.default.randomBytes(16);
|
|
166
|
-
const cipher = node_crypto.default.createCipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
|
|
167
|
-
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
|
|
168
|
-
return `${iv.toString("hex")}:${encrypted.toString("hex")}`;
|
|
169
|
-
}
|
|
170
|
-
decrypt(text) {
|
|
171
|
-
const textParts = text.split(":");
|
|
172
|
-
const iv = Buffer.from(textParts.shift(), "hex");
|
|
173
|
-
const encryptedText = Buffer.from(textParts.join(":"), "hex");
|
|
174
|
-
const decipher = node_crypto.default.createDecipheriv("aes-256-cbc", Buffer.from(this.apiConfig.key), iv);
|
|
175
|
-
const decrypted = Buffer.concat([decipher.update(encryptedText), decipher.final()]);
|
|
176
|
-
return decrypted.toString();
|
|
177
|
-
}
|
|
178
|
-
async getTheUserWhoIsLiveStreaming() {
|
|
179
|
-
const { data } = await this.client.get(GET_LATEST_UPDATED_UPS);
|
|
180
|
-
return data;
|
|
181
|
-
}
|
|
182
|
-
async getLiveRoomInfoStreamKey(roomId) {
|
|
183
|
-
const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO_STREAM_KEY}?id=${roomId}`);
|
|
184
|
-
return data;
|
|
185
|
-
}
|
|
186
|
-
async getLiveRoomInfoByUids(uids) {
|
|
187
|
-
const params = uids.map((uid) => `uids[]=${uid}`).join("&");
|
|
188
|
-
const { data } = await this.client.get(`${GET_LIVE_ROOMS_INFO}?${params}`);
|
|
189
|
-
return data;
|
|
190
|
-
}
|
|
191
|
-
async getServerUTCTime() {
|
|
192
|
-
const { data } = await this.client.get(GET_SERVER_UTC_TIME);
|
|
193
|
-
const regex = /Date\.UTC\((.*?)\)/;
|
|
194
|
-
const match = data.match(regex);
|
|
195
|
-
if (match) {
|
|
196
|
-
const timestamp = new Function(`return Date.UTC(${match[1]})`)();
|
|
197
|
-
return timestamp / 1e3;
|
|
198
|
-
}
|
|
199
|
-
throw new Error("解析服务器时间失败!");
|
|
200
|
-
}
|
|
201
|
-
async getTimeNow() {
|
|
202
|
-
const { data } = await this.client.get(GET_TIME_NOW);
|
|
203
|
-
return data;
|
|
204
|
-
}
|
|
205
|
-
async getAllGroup() {
|
|
206
|
-
const { data } = await this.client.get(GET_ALL_GROUP);
|
|
207
|
-
return data;
|
|
208
|
-
}
|
|
209
|
-
async removeUserFromGroup(mid) {
|
|
210
|
-
const csrf = this.getCSRF();
|
|
211
|
-
const { data } = await this.client.post(MODIFY_GROUP_MEMBER, {
|
|
212
|
-
fids: mid,
|
|
213
|
-
tagids: 0,
|
|
214
|
-
csrf
|
|
215
|
-
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
216
|
-
return data;
|
|
217
|
-
}
|
|
218
|
-
async copyUserToGroup(mid, groupId) {
|
|
219
|
-
const csrf = this.getCSRF();
|
|
220
|
-
const { data } = await this.client.post(COPY_USER_TO_GROUP, {
|
|
221
|
-
fids: mid,
|
|
222
|
-
tagids: groupId,
|
|
223
|
-
csrf
|
|
224
|
-
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
225
|
-
return data;
|
|
226
|
-
}
|
|
227
|
-
async getUserSpaceDynamic(mid) {
|
|
228
|
-
const { data } = await this.client.get(`${GET_USER_SPACE_DYNAMIC_LIST}&host_mid=${mid}`);
|
|
229
|
-
return data;
|
|
230
|
-
}
|
|
231
|
-
async createGroup(tag) {
|
|
232
|
-
const { data } = await this.client.post(CREATE_GROUP, {
|
|
233
|
-
tag,
|
|
234
|
-
csrf: this.getCSRF()
|
|
235
|
-
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
236
|
-
return data;
|
|
237
|
-
}
|
|
238
|
-
async getAllDynamic() {
|
|
239
|
-
const { data } = await this.client.get(GET_ALL_DYNAMIC_LIST);
|
|
240
|
-
return data;
|
|
241
|
-
}
|
|
242
|
-
async hasNewDynamic(updateBaseline) {
|
|
243
|
-
const { data } = await this.client.get(`${HAS_NEW_DYNAMIC}?update_baseline=${updateBaseline}`);
|
|
244
|
-
return data;
|
|
245
|
-
}
|
|
246
|
-
async follow(fid) {
|
|
247
|
-
const { data } = await this.client.post(MODIFY_RELATION, {
|
|
248
|
-
fid,
|
|
249
|
-
act: 1,
|
|
250
|
-
re_src: 11,
|
|
251
|
-
csrf: this.getCSRF()
|
|
252
|
-
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
253
|
-
return data;
|
|
254
|
-
}
|
|
255
|
-
async getRelationGroupDetail(tagid) {
|
|
256
|
-
const { data } = await this.client.get(`${GET_RELATION_GROUP_DETAIL}?tagid=${tagid}`);
|
|
257
|
-
return data;
|
|
258
|
-
}
|
|
259
|
-
async getCookieInfo(refreshToken) {
|
|
260
|
-
const { data } = await this.client.get(`${GET_COOKIES_INFO}?csrf=${refreshToken}`);
|
|
261
|
-
return data;
|
|
262
|
-
}
|
|
263
|
-
async getUserInfo(mid) {
|
|
264
|
-
if (mid === "11783021") {
|
|
265
|
-
console.log("检测到番剧出差UID,跳过远程用户接口访问");
|
|
266
|
-
return bangumiTripData;
|
|
267
|
-
}
|
|
268
|
-
const wbi = await this.getWbi({ mid });
|
|
269
|
-
const { data } = await this.client.get(`${GET_USER_INFO}?${wbi}`);
|
|
270
|
-
return data;
|
|
271
|
-
}
|
|
272
|
-
async getWbiKeys() {
|
|
273
|
-
const { data } = await this.client.get("https://api.bilibili.com/x/web-interface/nav");
|
|
274
|
-
const { data: { wbi_img: { img_url, sub_url } } } = data;
|
|
275
|
-
return {
|
|
276
|
-
img_key: img_url.slice(img_url.lastIndexOf("/") + 1, img_url.lastIndexOf(".")),
|
|
277
|
-
sub_key: sub_url.slice(sub_url.lastIndexOf("/") + 1, sub_url.lastIndexOf("."))
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
async getMyselfInfo() {
|
|
281
|
-
const { data } = await this.client.get(GET_MYSELF_INFO);
|
|
282
|
-
return data;
|
|
283
|
-
}
|
|
284
|
-
async getLoginQRCode() {
|
|
285
|
-
const { data } = await this.client.get(GET_LOGIN_QRCODE);
|
|
286
|
-
return data;
|
|
287
|
-
}
|
|
288
|
-
async getLoginStatus(qrcodeKey) {
|
|
289
|
-
const { data } = await this.client.get(`${GET_LOGIN_STATUS}?qrcode_key=${qrcodeKey}`);
|
|
290
|
-
return data;
|
|
291
|
-
}
|
|
292
|
-
async getLiveRoomInfo(roomId) {
|
|
293
|
-
const { data } = await this.client.get(`${GET_LIVE_ROOM_INFO}?room_id=${roomId}`);
|
|
294
|
-
return data;
|
|
295
|
-
}
|
|
296
|
-
async getMasterInfo(mid) {
|
|
297
|
-
const { data } = await this.client.get(`${GET_MASTER_INFO}?uid=${mid}`);
|
|
298
|
-
return data;
|
|
299
|
-
}
|
|
300
|
-
disposeNotifier() {
|
|
301
|
-
if (this.loginNotifier) this.loginNotifier.dispose();
|
|
302
|
-
}
|
|
303
|
-
getRandomUserAgent() {
|
|
304
|
-
const userAgents = [
|
|
305
|
-
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
|
|
306
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
|
|
307
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
|
|
308
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0",
|
|
309
|
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
|
|
310
|
-
];
|
|
311
|
-
const index = Math.floor(Math.random() * userAgents.length);
|
|
312
|
-
return userAgents[index];
|
|
313
|
-
}
|
|
314
|
-
createNewClient() {
|
|
315
|
-
this.jar = new tough_cookie.CookieJar();
|
|
316
|
-
this.client = (0, axios_cookiejar_support.wrapper)(axios.default.create({
|
|
317
|
-
jar: this.jar,
|
|
318
|
-
headers: {
|
|
319
|
-
"Content-Type": "application/json",
|
|
320
|
-
"User-Agent": this.apiConfig.userAgent !== "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" ? this.apiConfig.userAgent : this.getRandomUserAgent(),
|
|
321
|
-
Origin: "https://www.bilibili.com",
|
|
322
|
-
Referer: "https://www.bilibili.com/"
|
|
323
|
-
}
|
|
324
|
-
}));
|
|
325
|
-
}
|
|
326
|
-
getCookies() {
|
|
327
|
-
const cookies = JSON.stringify(this.jar.serializeSync().cookies);
|
|
328
|
-
return cookies;
|
|
329
|
-
}
|
|
330
|
-
async getCookiesForHeader() {
|
|
331
|
-
try {
|
|
332
|
-
const cookies = this.jar.serializeSync().cookies;
|
|
333
|
-
const cookieHeader = cookies.map((cookie) => `${cookie.key}=${cookie.value}`).join("; ");
|
|
334
|
-
return cookieHeader;
|
|
335
|
-
} catch (e) {
|
|
336
|
-
console.error("无效的 JSON 格式:", e);
|
|
337
|
-
return "";
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
getLoginInfoIsLoaded() {
|
|
341
|
-
return this.loginInfoIsLoaded;
|
|
342
|
-
}
|
|
343
|
-
async getLoginInfoFromDB() {
|
|
344
|
-
const data = (await this.ctx.database.get("loginBili", 1))[0];
|
|
345
|
-
if (data === void 0) {
|
|
346
|
-
this.loginNotifier = this.ctx.notifier.create({
|
|
347
|
-
type: "warning",
|
|
348
|
-
content: "您尚未登录,将无法使用插件提供的指令"
|
|
349
|
-
});
|
|
350
|
-
return {
|
|
351
|
-
cookies: null,
|
|
352
|
-
refresh_token: null
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
try {
|
|
356
|
-
const decryptedCookies = this.decrypt(data.bili_cookies);
|
|
357
|
-
const decryptedRefreshToken = this.decrypt(data.bili_refresh_token);
|
|
358
|
-
const cookies = JSON.parse(decryptedCookies);
|
|
359
|
-
return {
|
|
360
|
-
cookies,
|
|
361
|
-
refresh_token: decryptedRefreshToken
|
|
362
|
-
};
|
|
363
|
-
} catch (e) {
|
|
364
|
-
this.loginNotifier = this.ctx.notifier.create({
|
|
365
|
-
type: "warning",
|
|
366
|
-
content: "数据库被篡改,请重新登录"
|
|
367
|
-
});
|
|
368
|
-
await this.ctx.database.remove("loginBili", [1]);
|
|
369
|
-
return {
|
|
370
|
-
cookies: null,
|
|
371
|
-
refresh_token: null
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
getCSRF() {
|
|
376
|
-
return this.jar.serializeSync().cookies.find((cookie) => cookie.key === "bili_jct").value;
|
|
377
|
-
}
|
|
378
|
-
async loadCookiesFromDatabase() {
|
|
379
|
-
const { cookies, refresh_token } = await this.getLoginInfoFromDB();
|
|
380
|
-
if (!cookies || !refresh_token) {
|
|
381
|
-
this.loginInfoIsLoaded = true;
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
let csrf;
|
|
385
|
-
let expires;
|
|
386
|
-
let domain;
|
|
387
|
-
let path;
|
|
388
|
-
let secure;
|
|
389
|
-
let httpOnly;
|
|
390
|
-
let sameSite;
|
|
391
|
-
for (const cookieData of cookies) {
|
|
392
|
-
if (cookieData.key === "bili_jct") {
|
|
393
|
-
csrf = cookieData.value;
|
|
394
|
-
expires = new Date(cookieData.expires);
|
|
395
|
-
domain = cookieData.domain;
|
|
396
|
-
path = cookieData.path;
|
|
397
|
-
secure = cookieData.secure;
|
|
398
|
-
httpOnly = cookieData.httpOnly;
|
|
399
|
-
sameSite = cookieData.sameSite;
|
|
400
|
-
}
|
|
401
|
-
const cookie = new tough_cookie.Cookie({
|
|
402
|
-
key: cookieData.key,
|
|
403
|
-
value: cookieData.value,
|
|
404
|
-
expires: new Date(cookieData.expires),
|
|
405
|
-
domain: cookieData.domain,
|
|
406
|
-
path: cookieData.path,
|
|
407
|
-
secure: cookieData.secure,
|
|
408
|
-
httpOnly: cookieData.httpOnly,
|
|
409
|
-
sameSite: cookieData.sameSite
|
|
410
|
-
});
|
|
411
|
-
this.jar.setCookieSync(cookie, `http${cookie.secure ? "s" : ""}://${cookie.domain}${cookie.path}`, {});
|
|
412
|
-
}
|
|
413
|
-
const buvid3Cookie = new tough_cookie.Cookie({
|
|
414
|
-
key: "buvid3",
|
|
415
|
-
value: "some_non_empty_value",
|
|
416
|
-
expires,
|
|
417
|
-
domain,
|
|
418
|
-
path,
|
|
419
|
-
secure,
|
|
420
|
-
httpOnly,
|
|
421
|
-
sameSite
|
|
422
|
-
});
|
|
423
|
-
this.jar.setCookieSync(buvid3Cookie, `http${buvid3Cookie.secure ? "s" : ""}://${buvid3Cookie.domain}${buvid3Cookie.path}`, {});
|
|
424
|
-
this.loginInfoIsLoaded = true;
|
|
425
|
-
this.checkIfTokenNeedRefresh(refresh_token, csrf);
|
|
426
|
-
this.enableRefreshCookiesDetect();
|
|
427
|
-
}
|
|
428
|
-
enableRefreshCookiesDetect() {
|
|
429
|
-
if (this.refreshCookieTimer) this.refreshCookieTimer();
|
|
430
|
-
this.refreshCookieTimer = this.ctx.setInterval(async () => {
|
|
431
|
-
const { cookies, refresh_token } = await this.getLoginInfoFromDB();
|
|
432
|
-
if (!cookies || !refresh_token) return;
|
|
433
|
-
const csrf = cookies.find((cookie) => {
|
|
434
|
-
if (cookie.key === "bili_jct") return true;
|
|
435
|
-
}).value;
|
|
436
|
-
this.checkIfTokenNeedRefresh(refresh_token, csrf);
|
|
437
|
-
}, 36e5);
|
|
438
|
-
}
|
|
439
|
-
async checkIfTokenNeedRefresh(refreshToken, csrf, times = 3) {
|
|
440
|
-
const notifyAndError = (info) => {
|
|
441
|
-
this.loginNotifier = this.ctx.notifier.create({
|
|
442
|
-
type: "warning",
|
|
443
|
-
content: info
|
|
444
|
-
});
|
|
445
|
-
this.createNewClient();
|
|
446
|
-
this.refreshCookieTimer();
|
|
447
|
-
throw new Error(info);
|
|
448
|
-
};
|
|
449
|
-
try {
|
|
450
|
-
const { data } = await this.getCookieInfo(refreshToken);
|
|
451
|
-
if (!data.refresh) return;
|
|
452
|
-
} catch (e) {
|
|
453
|
-
if (times >= 1) this.ctx.setTimeout(() => {
|
|
454
|
-
this.checkIfTokenNeedRefresh(refreshToken, csrf, times - 1);
|
|
455
|
-
}, 3e3);
|
|
456
|
-
}
|
|
457
|
-
const publicKey = await node_crypto.default.subtle.importKey("jwk", {
|
|
458
|
-
kty: "RSA",
|
|
459
|
-
n: "y4HdjgJHBlbaBN04VERG4qNBIFHP6a3GozCl75AihQloSWCXC5HDNgyinEnhaQ_4-gaMud_GF50elYXLlCToR9se9Z8z433U3KjM-3Yx7ptKkmQNAMggQwAVKgq3zYAoidNEWuxpkY_mAitTSRLnsJW-NCTa0bqBFF6Wm1MxgfE",
|
|
460
|
-
e: "AQAB"
|
|
461
|
-
}, {
|
|
462
|
-
name: "RSA-OAEP",
|
|
463
|
-
hash: "SHA-256"
|
|
464
|
-
}, true, ["encrypt"]);
|
|
465
|
-
async function getCorrespondPath(timestamp) {
|
|
466
|
-
const data = new TextEncoder().encode(`refresh_${timestamp}`);
|
|
467
|
-
const encrypted = new Uint8Array(await node_crypto.default.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data));
|
|
468
|
-
return encrypted.reduce((str, c) => str + c.toString(16).padStart(2, "0"), "");
|
|
469
|
-
}
|
|
470
|
-
const ts = Date.now();
|
|
471
|
-
const correspondPath = await getCorrespondPath(ts);
|
|
472
|
-
const { data: refreshCsrfHtml } = await this.client.get(`https://www.bilibili.com/correspond/1/${correspondPath}`);
|
|
473
|
-
const { document } = new jsdom.JSDOM(refreshCsrfHtml).window;
|
|
474
|
-
const targetElement = document.getElementById("1-name");
|
|
475
|
-
const refresh_csrf = targetElement ? targetElement.textContent : null;
|
|
476
|
-
const { data: refreshData } = await this.client.post("https://passport.bilibili.com/x/passport-login/web/cookie/refresh", {
|
|
477
|
-
csrf,
|
|
478
|
-
refresh_csrf,
|
|
479
|
-
source: "main_web",
|
|
480
|
-
refresh_token: refreshToken
|
|
481
|
-
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
482
|
-
switch (refreshData.code) {
|
|
483
|
-
case -101: return this.createNewClient();
|
|
484
|
-
case -111: {
|
|
485
|
-
await this.ctx.database.remove("loginBili", [1]);
|
|
486
|
-
notifyAndError("csrf 校验错误,请重新登录");
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
489
|
-
case 86095: {
|
|
490
|
-
await this.ctx.database.remove("loginBili", [1]);
|
|
491
|
-
notifyAndError("refresh_csrf 错误或 refresh_token 与 cookie 不匹配,请重新登录");
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
const encryptedCookies = this.encrypt(this.getCookies());
|
|
495
|
-
const encryptedRefreshToken = this.encrypt(refreshData.data.refresh_token);
|
|
496
|
-
await this.ctx.database.upsert("loginBili", [{
|
|
497
|
-
id: 1,
|
|
498
|
-
bili_cookies: encryptedCookies,
|
|
499
|
-
bili_refresh_token: encryptedRefreshToken
|
|
500
|
-
}]);
|
|
501
|
-
const newCsrf = this.jar.serializeSync().cookies.find((cookie) => {
|
|
502
|
-
if (cookie.key === "bili_jct") return true;
|
|
503
|
-
}).value;
|
|
504
|
-
const { data: aceeptData } = await this.client.post("https://passport.bilibili.com/x/passport-login/web/confirm/refresh", {
|
|
505
|
-
csrf: newCsrf,
|
|
506
|
-
refresh_token: refreshToken
|
|
507
|
-
}, { headers: { "Content-Type": "application/x-www-form-urlencoded" } });
|
|
508
|
-
switch (aceeptData.code) {
|
|
509
|
-
case -111: {
|
|
510
|
-
await this.ctx.database.remove("loginBili", [1]);
|
|
511
|
-
notifyAndError("csrf 校验失败,请重新登录");
|
|
512
|
-
break;
|
|
513
|
-
}
|
|
514
|
-
case -400: throw new Error("请求错误");
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
519
|
-
attempts: 3,
|
|
520
|
-
onFailure(error, attempts) {
|
|
521
|
-
this.logger.error(`getTheUserWhoIsLiveStreaming() 第${attempts}次失败: ${error.message}`);
|
|
522
|
-
}
|
|
523
|
-
})], BiliAPI.prototype, "getTheUserWhoIsLiveStreaming", null);
|
|
524
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
525
|
-
attempts: 3,
|
|
526
|
-
onFailure(error, attempts) {
|
|
527
|
-
this.logger.error(`getLiveRoomInfoStreamKey() 第${attempts}次失败: ${error.message}`);
|
|
528
|
-
}
|
|
529
|
-
})], BiliAPI.prototype, "getLiveRoomInfoStreamKey", null);
|
|
530
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
531
|
-
attempts: 3,
|
|
532
|
-
onFailure(error, attempts) {
|
|
533
|
-
this.logger.error(`getLiveRoomInfoByUids() 第${attempts}次失败: ${error.message}`);
|
|
534
|
-
}
|
|
535
|
-
})], BiliAPI.prototype, "getLiveRoomInfoByUids", null);
|
|
536
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
537
|
-
attempts: 3,
|
|
538
|
-
onFailure(error, attempts) {
|
|
539
|
-
this.logger.error(`getServerUTCTime() 第${attempts}次失败: ${error.message}`);
|
|
540
|
-
}
|
|
541
|
-
})], BiliAPI.prototype, "getServerUTCTime", null);
|
|
542
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
543
|
-
attempts: 3,
|
|
544
|
-
onFailure(error, attempts) {
|
|
545
|
-
this.logger.error(`getTimeNow() 第${attempts}次失败: ${error.message}`);
|
|
546
|
-
}
|
|
547
|
-
})], BiliAPI.prototype, "getTimeNow", null);
|
|
548
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
549
|
-
attempts: 3,
|
|
550
|
-
onFailure(error, attempts) {
|
|
551
|
-
this.logger.error(`getAllGroup() 第${attempts}次失败: ${error.message}`);
|
|
552
|
-
}
|
|
553
|
-
})], BiliAPI.prototype, "getAllGroup", null);
|
|
554
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
555
|
-
attempts: 3,
|
|
556
|
-
onFailure(error, attempts) {
|
|
557
|
-
this.logger.error(`removeUserFromGroup() 第${attempts}次失败: ${error.message}`);
|
|
558
|
-
}
|
|
559
|
-
})], BiliAPI.prototype, "removeUserFromGroup", null);
|
|
560
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
561
|
-
attempts: 3,
|
|
562
|
-
onFailure(error, attempts) {
|
|
563
|
-
this.logger.error(`copyUserToGroup() 第${attempts}次失败: ${error.message}`);
|
|
564
|
-
}
|
|
565
|
-
})], BiliAPI.prototype, "copyUserToGroup", null);
|
|
566
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
567
|
-
attempts: 3,
|
|
568
|
-
onFailure(error, attempts) {
|
|
569
|
-
this.logger.error(`getUserSpaceDynamic() 第${attempts}次失败: ${error.message}`);
|
|
570
|
-
}
|
|
571
|
-
})], BiliAPI.prototype, "getUserSpaceDynamic", null);
|
|
572
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
573
|
-
attempts: 3,
|
|
574
|
-
onFailure(error, attempts) {
|
|
575
|
-
this.logger.error(`createGroup() 第${attempts}次失败: ${error.message}`);
|
|
576
|
-
}
|
|
577
|
-
})], BiliAPI.prototype, "createGroup", null);
|
|
578
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
579
|
-
attempts: 3,
|
|
580
|
-
onFailure(error, attempts) {
|
|
581
|
-
this.logger.error(`getAllDynamic() 第${attempts}次失败: ${error.message}`);
|
|
582
|
-
}
|
|
583
|
-
})], BiliAPI.prototype, "getAllDynamic", null);
|
|
584
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
585
|
-
attempts: 3,
|
|
586
|
-
onFailure(error, attempts) {
|
|
587
|
-
this.logger.error(`hasNewDynamic() 第${attempts}次失败: ${error.message}`);
|
|
588
|
-
}
|
|
589
|
-
})], BiliAPI.prototype, "hasNewDynamic", null);
|
|
590
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
591
|
-
attempts: 3,
|
|
592
|
-
onFailure(error, attempts) {
|
|
593
|
-
this.logger.error(`follow() 第${attempts}次失败: ${error.message}`);
|
|
594
|
-
}
|
|
595
|
-
})], BiliAPI.prototype, "follow", null);
|
|
596
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
597
|
-
attempts: 3,
|
|
598
|
-
onFailure(error, attempts) {
|
|
599
|
-
this.logger.error(`getRelationGroupDetail() 第${attempts}次失败: ${error.message}`);
|
|
600
|
-
}
|
|
601
|
-
})], BiliAPI.prototype, "getRelationGroupDetail", null);
|
|
602
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
603
|
-
attempts: 3,
|
|
604
|
-
onFailure(error, attempts) {
|
|
605
|
-
this.logger.error(`getCookieInfo() 第${attempts}次失败: ${error.message}`);
|
|
606
|
-
}
|
|
607
|
-
})], BiliAPI.prototype, "getCookieInfo", null);
|
|
608
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
609
|
-
attempts: 3,
|
|
610
|
-
onFailure(error, attempts) {
|
|
611
|
-
this.logger.error(`getUserInfo() 第${attempts}次失败: ${error.message}`);
|
|
612
|
-
}
|
|
613
|
-
})], BiliAPI.prototype, "getUserInfo", null);
|
|
614
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
615
|
-
attempts: 3,
|
|
616
|
-
onFailure(error, attempts) {
|
|
617
|
-
this.logger.error(`getWbiKeys() 第${attempts}次失败: ${error.message}`);
|
|
618
|
-
}
|
|
619
|
-
})], BiliAPI.prototype, "getWbiKeys", null);
|
|
620
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
621
|
-
attempts: 3,
|
|
622
|
-
onFailure(error, attempts) {
|
|
623
|
-
this.logger.error(`getMyselfInfo() 第${attempts}次失败: ${error.message}`);
|
|
624
|
-
}
|
|
625
|
-
})], BiliAPI.prototype, "getMyselfInfo", null);
|
|
626
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
627
|
-
attempts: 3,
|
|
628
|
-
onFailure(error, attempts) {
|
|
629
|
-
this.logger.error(`getLoginQRCode() 第${attempts}次失败: ${error.message}`);
|
|
630
|
-
}
|
|
631
|
-
})], BiliAPI.prototype, "getLoginQRCode", null);
|
|
632
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
633
|
-
attempts: 3,
|
|
634
|
-
onFailure(error, attempts) {
|
|
635
|
-
this.logger.error(`getLoginStatus() 第${attempts}次失败: ${error.message}`);
|
|
636
|
-
}
|
|
637
|
-
})], BiliAPI.prototype, "getLoginStatus", null);
|
|
638
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
639
|
-
attempts: 3,
|
|
640
|
-
onFailure(error, attempts) {
|
|
641
|
-
this.logger.error(`getLiveRoomInfo() 第${attempts}次失败: ${error.message}`);
|
|
642
|
-
}
|
|
643
|
-
})], BiliAPI.prototype, "getLiveRoomInfo", null);
|
|
644
|
-
(0, import_decorate.default)([require_utils.Retry({
|
|
645
|
-
attempts: 3,
|
|
646
|
-
onFailure(error, attempts) {
|
|
647
|
-
this.logger.error(`getMasterInfo() 第${attempts}次失败: ${error.message}`);
|
|
648
|
-
}
|
|
649
|
-
})], BiliAPI.prototype, "getMasterInfo", null);
|
|
650
|
-
(function(_BiliAPI) {
|
|
651
|
-
const Config = _BiliAPI.Config = koishi.Schema.object({
|
|
652
|
-
userAgent: koishi.Schema.string(),
|
|
653
|
-
key: koishi.Schema.string().pattern(/^[0-9a-f]{32}$/).required()
|
|
654
|
-
});
|
|
655
|
-
})(BiliAPI || (BiliAPI = {}));
|
|
656
|
-
var biliAPI_default = BiliAPI;
|
|
657
|
-
|
|
658
|
-
//#endregion
|
|
659
|
-
Object.defineProperty(exports, 'biliAPI_default', {
|
|
660
|
-
enumerable: true,
|
|
661
|
-
get: function () {
|
|
662
|
-
return biliAPI_default;
|
|
663
|
-
}
|
|
664
|
-
});
|