🗑️ 增加几个 callback 处理

This commit is contained in:
BTMuli
2023-12-11 15:49:41 +08:00
parent 17744cc01d
commit 07e944859c
3 changed files with 53 additions and 2 deletions

View File

@@ -211,6 +211,9 @@ class TGClient {
case "getStatusBarHeight":
await this.getStatusBarHeight(callback);
break;
case "genAuthKey":
await this.genAuthKey(payload, callback);
break;
case "getCookieInfo":
await this.getCookieInfo(payload, callback);
break;
@@ -249,6 +252,13 @@ class TGClient {
case "share":
await this.share(payload, callback);
break;
case "share2":
await this.nullCallback(arg);
break;
// 监听滚动事件? payload:{direction: 0|1} 0:向上滚动 1:向下滚动
case "onBeginDragging":
await this.nullCallback(arg);
break;
// getNotificationSettings
default:
console.warn(`[${arg.windowLabel}] ${arg.payload}`);
@@ -289,6 +299,24 @@ class TGClient {
await this.callback(callback, data);
}
/**
* @func genAuthKey
* @since Beta v0.3.7
* @desc 获取米游社客户端的 authkey
* @param {Record<string, string>} payload - 请求参数
* @param {string} callback - 回调函数名
* @returns {void} - 无返回值
*/
async genAuthKey(payload: Record<string, string>, callback: string): Promise<void> {
const userStore = useUserStore();
const cookie = {
mid: userStore.cookie.mid,
stoken: userStore.cookie.stoken,
};
const res = await TGRequest.User.getAuthkey2(cookie, payload);
await this.callback(callback, res.data);
}
/**
* @func getCookieInfo
* @since Beta v0.3.4

View File

@@ -4,7 +4,7 @@
* @since Beta v0.3.6
*/
import { genAuthkey } from "./genAuthkey";
import { genAuthkey, genAuthkey2 } from "./genAuthkey";
import { getAbyss } from "./getAbyss";
import { getActionTicketBySToken } from "./getActionTicket";
import { getAnnoContent, getAnnoList } from "./getAnno";
@@ -33,6 +33,7 @@ const TGRequest = {
},
User: {
getAuthkey: genAuthkey,
getAuthkey2: genAuthkey2,
getGachaLog,
getRecord: getGameRecord,
byLoginTicket: {

View File

@@ -1,7 +1,7 @@
/**
* @file web/request/genAuthkey.ts
* @description 生成 authkey
* @since Beta v0.3.0
* @since Beta v0.3.7
*/
import { http } from "@tauri-apps/api";
@@ -39,3 +39,25 @@ export async function genAuthkey(
return res.data;
});
}
/**
* @description 生成 authkey
* @since Beta v0.3.0
* @param {Record<string, string>} cookie cookie // stoken_v2 & mid
* @param {object} payload payload
* @returns {Promise<string|TGApp.BBS.Response.Base>} authkey
*/
export async function genAuthkey2(
cookie: Record<string, string>,
payload: Record<string, string>,
): Promise<TGApp.BBS.Response.Base> {
const url = "https://api-takumi.mihoyo.com/binding/api/genAuthKey";
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(payload), "lk2", true);
return await http
.fetch<TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: header,
body: http.Body.json(payload),
})
.then((res) => res.data);
}