✏️ 修正剩余的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 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;
});