koishi-plugin-bilibili-notify 1.2.1 → 1.2.2-alpha.0
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/biliAPI.d.ts +0 -1
- package/lib/biliAPI.js +0 -44
- package/lib/comRegister.js +4 -0
- package/package.json +1 -1
- package/readme.md +1 -0
package/lib/biliAPI.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ declare class BiliAPI extends Service {
|
|
|
15
15
|
refreshCookieTimer: Function;
|
|
16
16
|
constructor(ctx: Context);
|
|
17
17
|
protected start(): void | Promise<void>;
|
|
18
|
-
test_refresh_token(): Promise<void>;
|
|
19
18
|
getServerUTCTime(): Promise<number>;
|
|
20
19
|
getTimeNow(): Promise<any>;
|
|
21
20
|
getUserSpaceDynamic(mid: string): Promise<any>;
|
package/lib/biliAPI.js
CHANGED
|
@@ -39,50 +39,6 @@ class BiliAPI extends koishi_1.Service {
|
|
|
39
39
|
this.loadCookiesFromDatabase();
|
|
40
40
|
// this.logger.info('BiliAPI已被注册到Context中')
|
|
41
41
|
}
|
|
42
|
-
async test_refresh_token() {
|
|
43
|
-
const publicKey = await crypto.subtle.importKey("jwk", {
|
|
44
|
-
kty: "RSA",
|
|
45
|
-
n: "y4HdjgJHBlbaBN04VERG4qNBIFHP6a3GozCl75AihQloSWCXC5HDNgyinEnhaQ_4-gaMud_GF50elYXLlCToR9se9Z8z433U3KjM-3Yx7ptKkmQNAMggQwAVKgq3zYAoidNEWuxpkY_mAitTSRLnsJW-NCTa0bqBFF6Wm1MxgfE",
|
|
46
|
-
e: "AQAB",
|
|
47
|
-
}, { name: "RSA-OAEP", hash: "SHA-256" }, true, ["encrypt"]);
|
|
48
|
-
async function getCorrespondPath(timestamp) {
|
|
49
|
-
const data = new TextEncoder().encode(`refresh_${timestamp}`);
|
|
50
|
-
const encrypted = new Uint8Array(await crypto.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data));
|
|
51
|
-
return encrypted.reduce((str, c) => str + c.toString(16).padStart(2, "0"), "");
|
|
52
|
-
}
|
|
53
|
-
const ts = Date.now();
|
|
54
|
-
const correspondPath = await getCorrespondPath(ts);
|
|
55
|
-
const { data } = await this.client.get(`https://www.bilibili.com/correspond/1/${correspondPath}`);
|
|
56
|
-
// 创建一个虚拟的DOM元素
|
|
57
|
-
const { document } = new jsdom_1.JSDOM(data).window;
|
|
58
|
-
// 提取标签name为1-name的内容
|
|
59
|
-
const targetElement = document.getElementById('1-name');
|
|
60
|
-
const refresh_csrf = targetElement ? targetElement.textContent : null;
|
|
61
|
-
// 获取csrf
|
|
62
|
-
let csrf;
|
|
63
|
-
const cookies = JSON.parse(this.getCookies());
|
|
64
|
-
cookies.forEach(cookie => {
|
|
65
|
-
if (cookie.key === 'bili_jct')
|
|
66
|
-
csrf = cookie.value;
|
|
67
|
-
});
|
|
68
|
-
// 读取数据库获取cookies
|
|
69
|
-
const database = (await this.ctx.database.get('loginBili', 1))[0];
|
|
70
|
-
// 获取refreshToken
|
|
71
|
-
const refresh_token = this.ctx.wbi.decrypt(database.bili_refresh_token);
|
|
72
|
-
// 发送请求
|
|
73
|
-
// const { data: refreshData } = await this.client.post(`https://passport.bilibili.com/x/passport-login/web/cookie/refresh?csrf=${csrf}&refresh_csrf=${refresh_csrf}&source=main_web&refresh_token=${refresh_token}`)
|
|
74
|
-
const { data: refreshData } = await this.client.post('https://passport.bilibili.com/x/passport-login/web/cookie/refresh', {
|
|
75
|
-
csrf,
|
|
76
|
-
refresh_csrf,
|
|
77
|
-
source: 'main_web',
|
|
78
|
-
refresh_token
|
|
79
|
-
}, {
|
|
80
|
-
headers: {
|
|
81
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
console.log(refreshData);
|
|
85
|
-
}
|
|
86
42
|
async getServerUTCTime() {
|
|
87
43
|
try {
|
|
88
44
|
const { data } = await this.client.get(GET_SERVER_UTC_TIME);
|
package/lib/comRegister.js
CHANGED
|
@@ -968,6 +968,10 @@ class ComRegister {
|
|
|
968
968
|
}
|
|
969
969
|
async getSubFromDatabase(ctx) {
|
|
970
970
|
this.logger.info('开始执行数据库读取操作');
|
|
971
|
+
// 检查登录状态
|
|
972
|
+
const isLogin = await this.checkIfIsLogin(ctx);
|
|
973
|
+
// log
|
|
974
|
+
this.logger.info(`登录状态:${isLogin}`);
|
|
971
975
|
// 如果未登录,则直接返回
|
|
972
976
|
if (!(await this.checkIfIsLogin(ctx)))
|
|
973
977
|
return;
|
package/package.json
CHANGED