✏️ 修正剩余的import

This commit is contained in:
目棃
2024-07-01 14:17:13 +08:00
parent d48e39e580
commit bdd5e99f95
27 changed files with 162 additions and 310 deletions

View File

@@ -5,9 +5,10 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import { getDeviceInfo } from "../../../utils/toolFunc";
import { getRequestHeader } from "../../../web/utils/getRequestHeader";
import { getDeviceInfo } from "../../../utils/toolFunc.js";
import { getRequestHeader } from "../../../web/utils/getRequestHeader.js";
const APP_ID = 8;
@@ -21,21 +22,16 @@ export async function getLoginQr(): Promise<
> {
const url = "https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode/fetch";
const device = getDeviceInfo("device_id");
const data = {
app_id: APP_ID,
device,
};
const data = { app_id: APP_ID, device };
const header = getRequestHeader({}, "POST", data, "common");
return await http
.fetch<TGApp.Plugins.Mys.GameLogin.GetLoginQrResponse | TGApp.BBS.Response.Base>(url, {
headers: header,
method: "POST",
body: http.Body.json(data),
})
.then((res) => {
if (res.data.retcode === 0) return res.data.data;
return <TGApp.BBS.Response.Base>res.data;
});
.fetch(url, { headers: header, method: "POST", body: http.Body.json(data) })
.then(
(res: Response<TGApp.Plugins.Mys.GameLogin.GetLoginQrResponse | TGApp.BBS.Response.Base>) => {
if (res.data.retcode === 0) return res.data.data;
return <TGApp.BBS.Response.Base>res.data;
},
);
}
/**
@@ -52,13 +48,13 @@ export async function getLoginStatus(
const data = { app_id: APP_ID, device, ticket };
const header = getRequestHeader({}, "POST", data, "common");
return await http
.fetch<TGApp.Plugins.Mys.GameLogin.GetLoginStatusResponse | TGApp.BBS.Response.Base>(url, {
headers: header,
method: "POST",
body: http.Body.json(data),
})
.then((res) => {
if (res.data.retcode === 0) return res.data.data;
return <TGApp.BBS.Response.Base>res.data;
});
.fetch(url, { headers: header, method: "POST", body: http.Body.json(data) })
.then(
(
res: Response<TGApp.Plugins.Mys.GameLogin.GetLoginStatusResponse | TGApp.BBS.Response.Base>,
) => {
if (res.data.retcode === 0) return res.data.data;
return <TGApp.BBS.Response.Base>res.data;
},
);
}

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import MysApi from "../api";
import MysApi from "../api/index.js";
/**
* @description 获取合集信息
@@ -23,15 +24,12 @@ export async function getCollectionData(
id: collectionId.toString(),
};
return await http
.fetch<TGApp.Plugins.Mys.Collection.Response>(url, {
.fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: MysApi.PostReferer,
},
headers: { "Content-Type": "application/json", Referer: MysApi.PostReferer },
query: params,
})
.then((res) => {
.then((res: Response<TGApp.Plugins.Mys.Collection.Response>) => {
console.log(res.data);
return res.data.data;
});
@@ -47,19 +45,12 @@ export async function getCollectionPosts(
collectionId: string,
): Promise<TGApp.Plugins.Mys.Collection.Data[]> {
const url = "https://bbs-api.miyoushe.com/post/wapi/getPostFullInCollection";
const params = {
collection_id: collectionId,
};
const params = { collection_id: collectionId };
return await http
.fetch<TGApp.Plugins.Mys.Collection.ResponsePosts>(url, {
.fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: MysApi.PostReferer,
},
headers: { "Content-Type": "application/json", Referer: MysApi.PostReferer },
query: params,
})
.then((res) => {
return res.data.data.posts;
});
.then((res: Response<TGApp.Plugins.Mys.Collection.ResponsePosts>) => res.data.data.posts);
}

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 获取表情包列表
@@ -14,8 +15,8 @@ import { http } from "@tauri-apps/api";
export async function getEmojis(): Promise<Record<string, string> | TGApp.BBS.Response.Base> {
const url = "https://bbs-api-static.miyoushe.com/misc/api/emoticon_set";
return await http
.fetch<TGApp.Plugins.Mys.Emoji.Response | TGApp.BBS.Response.Base>(url)
.then((res) => {
.fetch(url)
.then((res: Response<TGApp.Plugins.Mys.Emoji.Response | TGApp.BBS.Response.Base>) => {
if (res.data.retcode === 0) {
const emojis: Record<string, string> = {};
res.data.data.list.forEach((series) => {

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 获取特定论坛列表
@@ -18,19 +19,10 @@ async function getForumList(
type: number = 0,
): Promise<TGApp.Plugins.Mys.Forum.FullData> {
const url = "https://bbs-api.miyoushe.com/post/wapi/getForumPostList";
const params = {
forum_id: forumId.toString(),
sort_type: type.toString(),
};
const params = { forum_id: forumId.toString(), sort_type: type.toString() };
return await http
.fetch<TGApp.Plugins.Mys.Forum.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
query: params,
})
.then((res) => res.data.data);
.fetch(url, { method: "GET", headers: { "Content-Type": "application/json" }, query: params })
.then((res: Response<TGApp.Plugins.Mys.Forum.Response>) => res.data.data);
}
export default getForumList;

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 获取卡池信息
@@ -14,15 +15,8 @@ import { http } from "@tauri-apps/api";
async function getGachaData(): Promise<TGApp.Plugins.Mys.Gacha.Data[]> {
const url = "https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/gacha_pool?app_sn=ys_obc";
return await http
.fetch<TGApp.Plugins.Mys.Gacha.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.list;
});
.fetch(url, { method: "GET", headers: { "Content-Type": "application/json" } })
.then((res: Response<TGApp.Plugins.Mys.Gacha.Response>) => res.data.data.list);
}
export default getGachaData;

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 获取首页导航列表
@@ -14,18 +15,10 @@ import { http } from "@tauri-apps/api";
*/
async function getHomeNavigator(gid: number = 2): Promise<TGApp.BBS.Navigator.Navigator[]> {
const url = "https://bbs-api.miyoushe.com/apihub/api/home/new";
const params = {
gids: gid.toString(),
};
const params = { gids: gid.toString() };
return await http
.fetch<TGApp.BBS.Navigator.HomeResponse>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
query: params,
})
.then((res) => res.data.data.navigator);
.fetch(url, { method: "GET", headers: { "Content-Type": "application/json" }, query: params })
.then((res: Response<TGApp.BBS.Navigator.HomeResponse>) => res.data.data.navigator);
}
export default getHomeNavigator;

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 获取抽奖信息
@@ -16,18 +17,10 @@ async function getLotteryData(
lotteryId: string,
): Promise<TGApp.BBS.Response.Base | TGApp.Plugins.Mys.Lottery.FullData> {
const url = "https://bbs-api.miyoushe.com/painter/wapi/lottery/user/show";
const params = {
id: lotteryId,
};
const params = { id: lotteryId };
return await http
.fetch<TGApp.Plugins.Mys.Lottery.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
query: params,
})
.then((res) => {
.fetch(url, { method: "GET", headers: { "Content-Type": "application/json" }, query: params })
.then((res: Response<TGApp.BBS.Response.Base | TGApp.Plugins.Mys.Lottery.Response>) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
return res.data.data.show_lottery;
});

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 获取 News 列表
@@ -29,14 +30,8 @@ async function getNewsList(
last_id: lastId.toString(),
};
return await http
.fetch<TGApp.Plugins.Mys.News.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
query: params,
})
.then((res) => res.data.data);
.fetch(url, { method: "GET", headers: { "Content-Type": "application/json" }, query: params })
.then((res: Response<TGApp.Plugins.Mys.News.Response>) => res.data.data);
}
export default getNewsList;

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 深度优先遍历
@@ -34,14 +35,7 @@ export async function getPositionData(): Promise<TGApp.Plugins.Mys.Position.Data
const url =
"https://api-static.mihoyo.com/common/blackboard/ys_obc/v1/home/position?app_sn=ys_obc";
const res = await http
.fetch<TGApp.Plugins.Mys.Position.Response>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => {
return res.data.data.list;
});
.fetch(url, { method: "GET", headers: { "Content-Type": "application/json" } })
.then((res: Response<TGApp.Plugins.Mys.Position.Response>) => res.data.data.list);
return DfsObc(res);
}

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import MysApi from "../api";
import MysApi from "../api/index.js";
/**
* @description 获取帖子信息
@@ -20,17 +21,12 @@ async function getPostData(postId: number): Promise<TGApp.Plugins.Mys.Post.FullD
post_id: postId.toString(),
};
return await http
.fetch<TGApp.Plugins.Mys.Post.Response>(url, {
.fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Referer: MysApi.PostReferer,
},
headers: { "Content-Type": "application/json", Referer: MysApi.PostReferer },
query: params,
})
.then((res) => {
return res.data.data.post;
});
.then((res: Response<TGApp.Plugins.Mys.Post.Response>) => res.data.data.post);
}
export default getPostData;

View File

@@ -25,9 +25,7 @@ export async function getVoteInfo(id: string, uid: string): Promise<TGApp.Plugin
headers: { "Content-Type": "application/json", Referer: MysApi.PostReferer },
query: params,
})
.then((res: Response<TGApp.Plugins.Mys.Vote.InfoResponse>) => {
return res.data.data.data[0];
});
.then((res: Response<TGApp.Plugins.Mys.Vote.InfoResponse>) => res.data.data.data[0]);
}
/**
@@ -49,7 +47,5 @@ export async function getVoteResult(
headers: { "Content-Type": "application/json", Referer: MysApi.PostReferer },
query: params,
})
.then((res: Response<TGApp.Plugins.Mys.Vote.ResultResponse>) => {
return res.data.data.data[0];
});
.then((res: Response<TGApp.Plugins.Mys.Vote.ResultResponse>) => res.data.data.data[0]);
}

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 搜索帖子
@@ -20,23 +21,10 @@ async function searchPosts(
last_id: string,
): Promise<TGApp.Plugins.Mys.Search.PostsResponseData> {
const url = "https://bbs-api.miyoushe.com/post/wapi/searchPosts";
const params = {
gids: gid,
keyword,
last_id,
size: "20",
};
const params = { gids: gid, keyword, last_id, size: "20" };
return await http
.fetch<TGApp.Plugins.Mys.Search.PostsResponse>(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
query: params,
})
.then((res) => {
return res.data.data;
});
.fetch(url, { method: "GET", headers: { "Content-Type": "application/json" }, query: params })
.then((res: Response<TGApp.Plugins.Mys.Search.PostsResponse>) => res.data.data);
}
export default searchPosts;

View File

@@ -4,7 +4,7 @@
* @since Beta v0.4.6
*/
import { AppCharacterData, ArcBirCalendar, ArcBirRole } from "../../../data";
import { AppCharacterData, ArcBirCalendar, ArcBirRole } from "../../../data/index.js";
/**
* @description 判断今天是不是角色生日

View File

@@ -5,9 +5,10 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGConstant from "../constant/TGConstant";
import TGUtils from "../utils/TGUtils";
import TGConstant from "../constant/TGConstant.js";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 生成 authkey
@@ -29,12 +30,8 @@ export async function genAuthkey(
};
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "lk2", true);
return await http
.fetch<TGApp.Game.Gacha.AuthkeyResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
})
.then((res) => {
.fetch(url, { method: "POST", headers: header, body: http.Body.json(data) })
.then((res: Response<TGApp.Game.Gacha.AuthkeyResponse | TGApp.BBS.Response.Base>) => {
if (res.data.retcode === 0) return res.data.data.authkey;
return res.data;
});
@@ -54,10 +51,6 @@ export async function genAuthkey2(
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);
.fetch(url, { method: "POST", headers: header, body: http.Body.json(payload) })
.then((res: Response<TGApp.BBS.Response.Base>) => res.data);
}

View File

@@ -5,9 +5,10 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGApi from "../api/TGApi";
import TGUtils from "../utils/TGUtils";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 获取深渊信息
@@ -27,12 +28,8 @@ export async function getAbyss(
const params = { role_id, schedule_type, server: account.region };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
return await http
.fetch<TGApp.Game.Abyss.Response | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
query: params,
})
.then((res) => {
.fetch(url, { method: "GET", headers: header, query: params })
.then((res: Response<TGApp.Game.Abyss.Response | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data;
});

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGUtils from "../utils/TGUtils";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 通过 stoken 获取 ActionTicket
@@ -24,23 +25,10 @@ export async function getActionTicketBySToken(
UID: string,
): Promise<TGApp.BBS.Response.getActionTicketBySToken> {
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 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.getActionTicketBySToken>(url, {
method: "GET",
headers: header,
query: params,
})
.then((res) => {
return res.data;
});
.fetch(url, { method: "GET", headers: header, query: params })
.then((res: Response<TGApp.BBS.Response.getActionTicketBySToken>) => res.data);
}

View File

@@ -4,6 +4,7 @@
* @since Beta v0.4.4
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
export enum AnnoServer {
CN_ISLAND = "cn_gf01",
@@ -62,11 +63,8 @@ export async function getAnnoList(
url = "https://hk4e-api-os.hoyoverse.com/common/hk4e_global/announcement/api/getAnnList";
}
return await http
.fetch<TGApp.BBS.Announcement.ListResponse>(url, {
method: "GET",
query: params,
})
.then((res) => res.data.data);
.fetch(url, { method: "GET", query: params })
.then((res: Response<TGApp.BBS.Announcement.ListResponse>) => res.data.data);
}
/**
@@ -88,11 +86,8 @@ export async function getAnnoContent(
url = "https://hk4e-api-os.hoyoverse.com/common/hk4e_global/announcement/api/getAnnContent";
}
const annoContents: TGApp.BBS.Announcement.ContentItem[] = await http
.fetch<TGApp.BBS.Announcement.ContentResponse>(url, {
method: "GET",
query: params,
})
.then((res) => res.data.data.list);
.fetch(url, { method: "GET", query: params })
.then((res: Response<TGApp.BBS.Announcement.ContentResponse>) => res.data.data.list);
const annoContent = annoContents.find((item) => item.ann_id === annId);
if (annoContent != null) {
return annoContent;

View File

@@ -5,9 +5,10 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGApi from "../api/TGApi";
import TGUtils from "../utils/TGUtils";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 根据 stoken 获取 cookie_token
@@ -21,19 +22,12 @@ export async function getCookieTokenBySToken(
Stoken: string,
): Promise<string | TGApp.BBS.Response.Base> {
const url = TGApi.GameTokens.getCookieToken;
const cookie = {
mid: Mid,
stoken: Stoken,
};
const cookie = { mid: Mid, stoken: Stoken };
const params = { stoken: Stoken };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
return await http
.fetch<TGApp.BBS.Response.getCookieTokenBySToken | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
query: params,
})
.then((res) => {
.fetch(url, { method: "GET", headers: header, query: params })
.then((res: Response<TGApp.BBS.Response.getCookieTokenBySToken | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.cookie_token;
});
@@ -53,12 +47,11 @@ export async function getCookieTokenByGameToken(
const url = "https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken";
const data = { account_id: Number(accountId), game_token: gameToken };
return await http
.fetch<TGApp.BBS.Response.getCookieTokenByGameToken | TGApp.BBS.Response.Base>(url, {
method: "POST",
body: http.Body.json(data),
})
.then((res) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.cookie_token;
});
.fetch(url, { method: "POST", body: http.Body.json(data) })
.then(
(res: Response<TGApp.BBS.Response.getCookieTokenByGameToken | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.cookie_token;
},
);
}

View File

@@ -5,9 +5,10 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import { getInitDeviceInfo } from "../../utils/toolFunc";
import TGConstant from "../constant/TGConstant";
import { getInitDeviceInfo } from "../../utils/toolFunc.js";
import TGConstant from "../constant/TGConstant.js";
/**
* @description 获取设备指纹
@@ -93,12 +94,8 @@ export async function getDeviceFp(
Referer: "https://webstatic.mihoyo.com/",
};
info.device_fp = await http
.fetch<TGApp.BBS.Response.getDeviceFp>(url, {
method: "POST",
body: http.Body.json(data),
headers: header,
})
.then((res) => {
.fetch(url, { method: "POST", body: http.Body.json(data), headers: header })
.then((res: Response<TGApp.BBS.Response.getDeviceFp>) => {
if (res.data.data.code === 200) return res.data.data.device_fp;
return "0000000000000";
});

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 获取抽卡记录
@@ -31,11 +32,8 @@ export async function getGachaLog(
end_id: endId,
};
return await http
.fetch<TGApp.Game.Gacha.GachaLogResponse | TGApp.BBS.Response.Base>(url, {
method: "GET",
query: params,
})
.then((res) => {
.fetch(url, { method: "GET", query: params })
.then((res: Response<TGApp.Game.Gacha.GachaLogResponse | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
return res.data.data.list;
});

View File

@@ -5,10 +5,11 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGApi from "../api/TGApi";
import TGConstant from "../constant/TGConstant";
import TGUtils from "../utils/TGUtils";
import TGApi from "../api/TGApi.js";
import TGConstant from "../constant/TGConstant.js";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 通过 stoken 获取游戏账号
@@ -22,10 +23,7 @@ export async function getGameAccountsBySToken(
stuid: string,
): Promise<TGApp.User.Account.Game[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.bySToken.getAccounts;
const cookie = {
stuid,
stoken,
};
const cookie = { stuid, stoken };
const params = { stoken, stuid, game_biz: TGConstant.Utils.GAME_BIZ };
return await getGameAccounts(url, cookie, params);
}
@@ -42,10 +40,7 @@ export async function getGameAccountsByCookie(
account_id: string,
): Promise<TGApp.User.Account.Game[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.byCookie.getAccounts;
const cookie = {
account_id,
cookie_token,
};
const cookie = { account_id, cookie_token };
const params = { game_biz: TGConstant.Utils.GAME_BIZ };
return await getGameAccounts(url, cookie, params);
}
@@ -65,12 +60,8 @@ async function getGameAccounts(
): Promise<TGApp.BBS.Response.Base | TGApp.User.Account.Game[]> {
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
return await http
.fetch<TGApp.User.Account.GameResponse | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
query: params,
})
.then((res) => {
.fetch(url, { method: "GET", headers: header, query: params })
.then((res: Response<TGApp.User.Account.GameResponse | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
return res.data.data.list;
});

View File

@@ -5,9 +5,10 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGApi from "../api/TGApi";
import TGUtils from "../utils/TGUtils";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 根据 stoken_v2 获取 ltoken
@@ -21,19 +22,12 @@ export async function getLTokenBySToken(
Stoken: string,
): Promise<string | TGApp.BBS.Response.Base> {
const url = TGApi.GameTokens.getLToken;
const cookie = {
mid: Mid,
stoken: Stoken,
};
const cookie = { mid: Mid, stoken: Stoken };
const params = { stoken: Stoken };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
return await http
.fetch<TGApp.BBS.Response.getLTokenBySToken | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
query: params,
})
.then((res) => {
.fetch(url, { method: "GET", headers: header, query: params })
.then((res: Response<TGApp.BBS.Response.getLTokenBySToken | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.ltoken;
});

View File

@@ -5,9 +5,10 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGApi from "../api/TGApi";
import TGUtils from "../utils/TGUtils";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 通过 Cookie 获取用户角色列表
@@ -26,12 +27,8 @@ export async function getGameRoleListByLToken(
const data = { role_id: uid, server: TGUtils.Tools.getServerByUid(uid) };
const header = TGUtils.User.getHeader(cookie, "POST", JSON.stringify(data), "common");
return await http
.fetch<TGApp.Game.Character.ListResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
})
.then((res) => {
.fetch(url, { method: "POST", headers: header, body: http.Body.json(data) })
.then((res: Response<TGApp.Game.Character.ListResponse | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
return res.data.data.avatars;
});

View File

@@ -5,9 +5,10 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGConstant from "../constant/TGConstant";
import { getRequestHeader } from "../utils/getRequestHeader";
import TGConstant from "../constant/TGConstant.js";
import { getRequestHeader } from "../utils/getRequestHeader.js";
/**
* @description 获取 stoken
@@ -27,16 +28,10 @@ export async function getStokenByGameToken(
url = "https://api-takumi.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken";
}
const data = { account_id: Number(accountId), game_token: token };
const header = {
"x-rpc-app_id": TGConstant.BBS.APP_ID,
};
const header = { "x-rpc-app_id": TGConstant.BBS.APP_ID };
return await http
.fetch<TGApp.BBS.Response.getStokenByGameToken | TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: header,
body: http.Body.json(data),
})
.then((res) => {
.fetch(url, { method: "POST", headers: header, body: http.Body.json(data) })
.then((res: Response<TGApp.BBS.Response.getStokenByGameToken | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
return res.data.data;
});
@@ -54,20 +49,14 @@ export async function getTokenBySToken(
stuid: string,
): Promise<TGApp.BBS.Response.getTokenBySTokenData | TGApp.BBS.Response.Base> {
const url = "https://passport-api.mihoyo.com/account/ma-cn-session/app/getTokenBySToken";
const cookie = {
stoken,
stuid,
};
const cookie = { stoken, stuid };
const header = {
"x-rpc-app_id": TGConstant.BBS.APP_ID,
...getRequestHeader(cookie, "POST", "", "prod"),
};
return await http
.fetch<TGApp.BBS.Response.getTokenBySToken | TGApp.BBS.Response.Base>(url, {
method: "POST",
headers: header,
})
.then((res) => {
.fetch(url, { method: "POST", headers: header })
.then((res: Response<TGApp.BBS.Response.getTokenBySToken | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
return res.data.data;
});

View File

@@ -5,9 +5,10 @@
*/
import { app, http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGApi from "../api/TGApi";
import TGUtils from "../utils/TGUtils";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 获取同步角色详情
@@ -37,15 +38,13 @@ async function getSyncAvatarDetail(
Cookie: TGUtils.Tools.transCookie({ account_id: accountId, cookie_token: cookieToken }),
};
return await http
.fetch<TGApp.Game.Calculate.SyncAvatarDetailResponse | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
query: params,
})
.then((res) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
return res.data.data;
});
.fetch(url, { method: "GET", headers: header, query: params })
.then(
(res: Response<TGApp.Game.Calculate.SyncAvatarDetailResponse | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
return res.data.data;
},
);
}
export default getSyncAvatarDetail;

View File

@@ -5,9 +5,10 @@
*/
import { app, http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGApi from "../api/TGApi";
import TGUtils from "../utils/TGUtils";
import TGApi from "../api/TGApi.js";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 获取同步角色列表请求
@@ -23,11 +24,7 @@ async function getSyncAvatarList(
page: number,
): Promise<TGApp.Game.Calculate.AvatarListItem[] | TGApp.BBS.Response.Base> {
const url = TGApi.GameData.calculate.getSyncAvatarList; // 获取同步角色列表请求地址
const data = {
uid,
region: TGUtils.Tools.getServerByUid(uid),
page,
};
const data = { uid, region: TGUtils.Tools.getServerByUid(uid), page };
const version = await app.getVersion();
const header = {
"User-Agent": `TeyvatGuide/${version}`,
@@ -35,15 +32,13 @@ async function getSyncAvatarList(
Cookie: TGUtils.Tools.transCookie(cookie),
};
return await http
.fetch<TGApp.Game.Calculate.SyncAvatarListResponse | TGApp.BBS.Response.Base>(url, {
method: "POST",
body: http.Body.json(data),
headers: header,
})
.then((res) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.list;
});
.fetch(url, { method: "POST", body: http.Body.json(data), headers: header })
.then(
(res: Response<TGApp.Game.Calculate.SyncAvatarListResponse | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return res.data;
return res.data.data.list;
},
);
}
/**

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import TGUtils from "../utils/TGUtils";
import TGUtils from "../utils/TGUtils.js";
/**
* @description 获取用户收藏帖子
@@ -25,12 +26,8 @@ export async function getUserCollect(
const params = { size: "20", uid, offset };
const header = TGUtils.User.getHeader(cookie, "GET", params, "common");
return await http
.fetch<TGApp.BBS.Collection.PostResponse | TGApp.BBS.Response.Base>(url, {
method: "GET",
headers: header,
query: params,
})
.then((res) => {
.fetch(url, { method: "GET", headers: header, query: params })
.then((res: Response<TGApp.BBS.Collection.PostResponse | TGApp.BBS.Response.Base>) => {
if (res.data.retcode !== 0) return <TGApp.BBS.Response.Base>res.data;
return res.data.data;
});