🌱 完善 jsBridge

This commit is contained in:
BTMuli
2023-10-24 00:38:41 +08:00
parent 7ef89c33f1
commit 35dc972841
10 changed files with 255 additions and 25 deletions

View File

@@ -1,12 +1,12 @@
/**
* @file web request TGRequest.ts
* @description 应用用到的请求函数
* @author BTMuli <bt-muli@outlook.com>
* @since Beta v0.3.0
* @since Beta v0.3.4
*/
import { genAuthkey } from "./genAuthkey";
import { getAbyss } from "./getAbyss";
import { getActionTicketBySToken } from "./getActionTicket";
import { getAnnoContent, getAnnoList } from "./getAnno";
import { getCookieTokenByGameToken, getCookieTokenBySToken } from "./getCookieToken";
// import * from "./getEnkaData.ts";
@@ -48,6 +48,7 @@ const TGRequest = {
getAccounts: getGameAccountsBySToken,
getCookieToken: getCookieTokenBySToken,
getLToken: getLTokenBySToken,
getActionTicket: getActionTicketBySToken,
},
bgGameToken: {
getCookieToken: getCookieTokenByGameToken,

View File

@@ -15,7 +15,7 @@ import TGUtils from "../utils/TGUtils";
* @param {Record<string, string>} cookie cookie
* @param {string} schedule_type 1: 本期, 2: 上期
* @param {TGApp.Sqlite.Account.Game} account 游戏账号
* @returns {Promise<TGApp.Game.Abyss.FullData|TGApp.App.Base.Response>}
* @returns {Promise<TGApp.Game.Abyss.FullData|TGApp.BBS.Response.Base>}
*/
export async function getAbyss(
cookie: Record<string, string>,

View File

@@ -0,0 +1,47 @@
/**
* @file web/request/getActionTicket.ts
* @description 获取米游社动态的 ActionTicket
* @since Beta v0.3.4
*/
import { http } from "@tauri-apps/api";
import TGUtils from "../utils/TGUtils";
/**
* @description 通过 stoken 获取 ActionTicket
* @since Beta v0.3.4
* @todo 类型完善
* @param {string} ActionType 动作类型
* @param {string} SToken stoken
* @param {string} MID 用户 MID
* @param {string} UID 用户 UID
* @returns {Promise<TGApp.BBS.Response.Base>}
*/
export async function getActionTicketBySToken(
ActionType: string,
SToken: string,
MID: string,
UID: string,
): Promise<TGApp.BBS.Response.Base> {
const url = "https://api-takumi.mihoyo.com/auth/api/getActionTicketBySToken";
const params = {
action_type: ActionType,
stoken: SToken,
uid: UID,
};
const cookie = {
mid: MID,
stoken: SToken,
};
const header = TGUtils.User.getHeader(cookie, "GET", params, "k2");
return await http
.fetch<TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
query: params,
})
.then((res) => {
return res.data;
});
}

View File

@@ -1,7 +1,7 @@
/**
* @file web request getUserInfo.ts
* @description 获取用户信息请求
* @since Beta v0.3.3
* @since Beta v0.3.4
*/
import { http } from "@tauri-apps/api";
@@ -11,15 +11,28 @@ import TGUtils from "../utils/TGUtils";
/**
* @description 根据 cookie 获取用户信息
* @since Beta v0.3.3
* @since Beta v0.3.4
* @todo 完善
* @param {string} cookie_token cookie token
* @param {string} account_id 用户 account_id
* @returns {Promise<TGApp.App.Account.BriefInfo | TGApp.BBS.Response.Base>}
* @param {boolean} return_full 是否返回完整信息
* @returns {Promise<TGApp.App.Account.BriefInfo | TGApp.Plugins.Mys.User.Info>}
*/
export async function getUserInfoByCookie(
cookie_token: string,
account_id: string,
): Promise<TGApp.App.Account.BriefInfo | TGApp.BBS.Response.Base> {
return_full: false,
): Promise<TGApp.App.Account.BriefInfo | TGApp.BBS.Response.Base>;
export async function getUserInfoByCookie(
cookie_token: string,
account_id: string,
return_full: true,
): Promise<TGApp.Plugins.Mys.User.Info | TGApp.BBS.Response.Base>;
export async function getUserInfoByCookie(
cookie_token: string,
account_id: string,
return_full: boolean = false,
): Promise<TGApp.App.Account.BriefInfo | TGApp.BBS.Response.Base | TGApp.Plugins.Mys.User.Info> {
const cookie = {
cookie_token,
account_id,
@@ -36,6 +49,7 @@ export async function getUserInfoByCookie(
.then((res) => {
if (res.data.retcode !== 0) return res.data;
const info = res.data.data.user_info;
if (return_full === undefined || return_full) return info;
return {
nickname: info.nickname,
uid: info.uid,

View File

@@ -1,14 +1,13 @@
/**
* @file web utils TGUtils.ts
* @description 应用用到的工具函数
* @author BTMuli <bt-muli@outlook.com>
* @since Beta v0.3.0
* @since Beta v0.3.4
*/
import { getAnnoCard } from "./getAnnoCard";
import { getRequestHeader } from "./getRequestHeader";
import { getRequestHeader, getRandomString, getRandomNumber } from "./getRequestHeader";
import { parseAnnoContent } from "./parseAnno";
import { getServerByUid, transCookie } from "./tools";
import { getServerByUid, transCookie, transParams } from "./tools";
const TGUtils = {
Anno: {
@@ -21,6 +20,9 @@ const TGUtils = {
Tools: {
getServerByUid,
transCookie,
getRandomString,
getRandomNumber,
transParams,
},
};

View File

@@ -36,7 +36,7 @@ function getSalt(saltType: string): string {
* @param {number} max 最大值
* @returns {number} 随机数
*/
function getRandomNumber(min: number, max: number): number {
export function getRandomNumber(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}