✏️ 继续修正 import

This commit is contained in:
目棃
2024-06-26 22:28:05 +08:00
parent f2e4186042
commit 0061dfa988
44 changed files with 198 additions and 230 deletions

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import { Response } from "@tauri-apps/api/http";
/**
* @description Bili 插件导航请求
@@ -13,7 +14,7 @@ import { http } from "@tauri-apps/api";
*/
async function getNav(): Promise<TGApp.Plugins.Bili.Nav.NavData> {
const url = "https://api.bilibili.com/x/web-interface/nav";
return await http.fetch<TGApp.Plugins.Bili.Nav.NavResponse>(url).then((res) => {
return await http.fetch(url).then((res: Response<TGApp.Plugins.Bili.Nav.NavResponse>) => {
return res.data.data;
});
}

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import { Response } from "@tauri-apps/api/http";
import getWrid from "../utils/getWrid";
import getWrid from "../utils/getWrid.js";
/**
* @description 获取视频播放地址
@@ -31,14 +32,14 @@ async function getVideoUrl(cid: number, bvid: string): Promise<TGApp.Plugins.Bil
wrid: wridRes[1],
};
return await http
.fetch<TGApp.Plugins.Bili.Video.UrlResponse>(url, {
.fetch(url, {
method: "GET",
query: params,
headers: {
referer: "https://www.bilibili.com/",
},
})
.then((res) => {
.then((res: Response<TGApp.Plugins.Bili.Video.UrlResponse>) => {
return res.data.data;
});
}

View File

@@ -5,6 +5,7 @@
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
/**
* @description 获取视频基本信息
@@ -26,10 +27,8 @@ async function getVideoView(
throw new Error("参数错误");
}
return await http
.fetch<TGApp.Plugins.Bili.Video.ViewResponse>(url, {
method: "GET",
})
.then((res) => {
.fetch(url, { method: "GET" })
.then((res: Response<TGApp.Plugins.Bili.Video.ViewResponse>) => {
return res.data.data;
});
}

View File

@@ -6,7 +6,7 @@
import md5 from "js-md5";
import getNav from "../request/getNav";
import getNav from "../request/getNav.js";
/**
* @description 获取 key 值

View File

@@ -5,15 +5,15 @@
* @since Beta v0.3.0
*/
import getAvatarCollect from "./request/getAvatarCollect";
import getAvatarHoldRate from "./request/getAvatarHoldRate";
import getAvatarUpRate from "./request/getAvatarUpRate";
import getAvatarUseRate from "./request/getAvatarUseRate";
import getOverview from "./request/getOverview";
import getTeamCollect from "./request/getTeamCollect";
import getWeaponCollect from "./request/getWeaponCollect";
import uploadData from "./request/uploadData";
import { transAvatars, transLocal } from "./utils/transLocal";
import getAvatarCollect from "./request/getAvatarCollect.js";
import getAvatarHoldRate from "./request/getAvatarHoldRate.js";
import getAvatarUpRate from "./request/getAvatarUpRate.js";
import getAvatarUseRate from "./request/getAvatarUseRate.js";
import getOverview from "./request/getOverview.js";
import getTeamCollect from "./request/getTeamCollect.js";
import getWeaponCollect from "./request/getWeaponCollect.js";
import uploadData from "./request/uploadData.js";
import { transAvatars, transLocal } from "./utils/transLocal.js";
const Hutao = {
Abyss: {

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import { Response } from "@tauri-apps/api/http";
import HutaoApi from "../api";
import HutaoApi from "../api/index.js";
/**
* @description 获取角色搭配数据
@@ -16,10 +17,8 @@ import HutaoApi from "../api";
async function getAvatarCollect(): Promise<TGApp.Plugins.Hutao.Abyss.AvatarCollocation[]> {
const url = HutaoApi.Abyss.avatar.collect;
return await http
.fetch<TGApp.Plugins.Hutao.Abyss.AvatarCollocationResponse>(url, {
method: "GET",
})
.then((res) => {
.fetch(url, { method: "GET" })
.then((res: Response<TGApp.Plugins.Hutao.Abyss.AvatarCollocationResponse>) => {
return res.data.data;
});
}

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import { Response } from "@tauri-apps/api/http";
import HutaoApi from "../api";
import HutaoApi from "../api/index.js";
/**
* @description 获取角色持有率数据
@@ -16,10 +17,8 @@ import HutaoApi from "../api";
async function getAvatarHoldRate(): Promise<TGApp.Plugins.Hutao.Abyss.AvatarHold[]> {
const url = HutaoApi.Abyss.avatar.holdRate;
return await http
.fetch<TGApp.Plugins.Hutao.Abyss.AvatarHoldResponse>(url, {
method: "GET",
})
.then((res) => {
.fetch(url, { method: "GET" })
.then((res: Response<TGApp.Plugins.Hutao.Abyss.AvatarHoldResponse>) => {
return res.data.data;
});
}

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import { Response } from "@tauri-apps/api/http";
import HutaoApi from "../api";
import HutaoApi from "../api/index.js";
/**
* @description 获取角色上场率数据
@@ -16,10 +17,8 @@ import HutaoApi from "../api";
async function getAvatarUpRate(): Promise<TGApp.Plugins.Hutao.Abyss.AvatarUp[]> {
const url = HutaoApi.Abyss.avatar.upRate;
return await http
.fetch<TGApp.Plugins.Hutao.Abyss.AvatarUpResponse>(url, {
method: "GET",
})
.then((res) => {
.fetch(url, { method: "GET" })
.then((res: Response<TGApp.Plugins.Hutao.Abyss.AvatarUpResponse>) => {
return res.data.data;
});
}

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import { Response } from "@tauri-apps/api/http";
import HutaoApi from "../api";
import HutaoApi from "../api/index.js";
/**
* @description 获取角色使用率
@@ -16,10 +17,8 @@ import HutaoApi from "../api";
async function getAvatarUseRate(): Promise<TGApp.Plugins.Hutao.Abyss.AvatarUse[]> {
const url = HutaoApi.Abyss.avatar.useRate;
return await http
.fetch<TGApp.Plugins.Hutao.Abyss.AvatarUseResponse>(url, {
method: "GET",
})
.then((res) => {
.fetch(url, { method: "GET" })
.then((res: Response<TGApp.Plugins.Hutao.Abyss.AvatarUseResponse>) => {
return res.data.data;
});
}

View File

@@ -5,8 +5,9 @@
*/
import { http } from "@tauri-apps/api";
import { Response } from "@tauri-apps/api/http";
import HutaoApi from "../api";
import HutaoApi from "../api/index.js";
/**
* @description 获取深渊概览数据
@@ -16,10 +17,8 @@ import HutaoApi from "../api";
async function getOverview(): Promise<TGApp.Plugins.Hutao.Abyss.OverviewData> {
const url = HutaoApi.Abyss.overview;
return await http
.fetch<TGApp.Plugins.Hutao.Abyss.OverviewResponse>(url, {
method: "GET",
})
.then((res) => {
.fetch(url, { method: "GET" })
.then((res: Response<TGApp.Plugins.Hutao.Abyss.OverviewResponse>) => {
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 HutaoApi from "../api";
import HutaoApi from "../api/index.js";
/**
* @description 获取队伍搭配数据
@@ -16,10 +17,8 @@ import HutaoApi from "../api";
async function getTeamCollect(): Promise<TGApp.Plugins.Hutao.Abyss.TeamCombination[]> {
const url = HutaoApi.Abyss.team;
return await http
.fetch<TGApp.Plugins.Hutao.Abyss.TeamCombinationResponse>(url, {
method: "GET",
})
.then((res) => {
.fetch(url, { method: "GET" })
.then((res: Response<TGApp.Plugins.Hutao.Abyss.TeamCombinationResponse>) => {
return res.data.data;
});
}

View File

@@ -1,13 +1,13 @@
/**
* @file plugins Hutao request getWeaponCollect.ts
* @description 获取武器搭配
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.0
*/
import { http } from "@tauri-apps/api";
import type { Response } from "@tauri-apps/api/http";
import HutaoApi from "../api";
import HutaoApi from "../api/index.js";
/**
* @description 获取武器搭配
@@ -17,10 +17,8 @@ import HutaoApi from "../api";
async function getWeaponCollect(): Promise<TGApp.Plugins.Hutao.Abyss.WeaponCollocation[]> {
const url = HutaoApi.Abyss.weapon;
return await http
.fetch<TGApp.Plugins.Hutao.Abyss.WeaponCollocationResponse>(url, {
method: "GET",
})
.then((res) => {
.fetch(url, { method: "GET" })
.then((res: Response<TGApp.Plugins.Hutao.Abyss.WeaponCollocationResponse>) => {
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 HutaoApi from "../api";
import HutaoApi from "../api/index.js";
/**
* @description 上传用户数据
@@ -19,11 +20,8 @@ async function uploadData(
): Promise<TGApp.Plugins.Hutao.Abyss.UploadResponse> {
const url = HutaoApi.Abyss.upload;
return await http
.fetch<TGApp.Plugins.Hutao.Abyss.UploadResponse>(url, {
method: "POST",
body: http.Body.json(data),
})
.then((res) => res.data);
.fetch(url, { method: "POST", body: http.Body.json(data) })
.then((res: Response<TGApp.Plugins.Hutao.Abyss.UploadResponse>) => res.data);
}
export default uploadData;

View File

@@ -86,11 +86,11 @@ function transLevel(data: TGApp.Sqlite.Abyss.Level): TGApp.Plugins.Hutao.Abyss.L
const battles: Array<{ Index: number; Avatars: number[] }> = [];
battles.push({
Index: 1,
Avatars: data.upBattle.characters.map((character) => character.id),
Avatars: data.upBattle!.characters.map((character) => character.id),
});
battles.push({
Index: 2,
Avatars: data.downBattle.characters.map((character) => character.id),
Avatars: data.downBattle!.characters.map((character) => character.id),
});
return {
Index: data.id,

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 获取投票信息
@@ -17,20 +18,14 @@ import MysApi from "../api";
*/
export async function getVoteInfo(id: string, uid: string): Promise<TGApp.Plugins.Mys.Vote.Info> {
const url = "https://bbs-api.miyoushe.com/apihub/api/getVotes";
const params = {
owner_uid: uid,
vote_ids: id,
};
const params = { owner_uid: uid, vote_ids: id };
return await http
.fetch<TGApp.Plugins.Mys.Vote.InfoResponse>(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.Vote.InfoResponse>) => {
return res.data.data.data[0];
});
}
@@ -47,20 +42,14 @@ export async function getVoteResult(
uid: string,
): Promise<TGApp.Plugins.Mys.Vote.Result> {
const url = "https://bbs-api.miyoushe.com/apihub/api/getVotesResult";
const params = {
owner_uid: uid,
vote_ids: id,
};
const params = { owner_uid: uid, vote_ids: id };
return await http
.fetch<TGApp.Plugins.Mys.Vote.ResultResponse>(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.Vote.ResultResponse>) => {
return res.data.data.data[0];
});
}

View File

@@ -4,8 +4,8 @@
* @since Beta v0.4.4
*/
import { AppCharacterData } from "../../../data";
import getPostData from "../request/getPostData";
import { AppCharacterData } from "../../../data/index.js";
import getPostData from "../request/getPostData.js";
/**
* @description 根据单个卡池信息转为渲染用的卡池信息

View File

@@ -1,13 +1,12 @@
/**
* @file plugins Mys utils getPositionCard.ts
* @file plugins/Mys/utils/getPositionCard.ts
* @description Mys 插件热点追踪工具
* @author BTMuli <bt-muli@outlook.com>
* @since Alpha v0.2.1
* @since Beta v0.4.10
*/
/**
* @description 根据热点追踪信息转为渲染用的数据
* @since Alpha v0.1.5
* @since Beta v0.4.10
* @param {TGApp.Plugins.Mys.Position.Data[]} positionData 列表
* @returns {TGApp.Plugins.Mys.Position.RenderCard[]} 返回列表
*/
@@ -15,14 +14,14 @@ function getPositionCard(
positionData: TGApp.Plugins.Mys.Position.Data[],
): TGApp.Plugins.Mys.Position.RenderCard[] {
const res: TGApp.Plugins.Mys.Position.RenderCard[] = [];
positionData.map((position) => {
for (const position of positionData) {
let endStr: string;
if (position.end_time === "0") {
endStr = "";
} else {
endStr = new Date(Number(position.end_time)).toLocaleDateString().replace(/\//g, "-");
}
return res.push<TGApp.Plugins.Mys.Position.RenderCard>({
const card: TGApp.Plugins.Mys.Position.RenderCard = {
title: position.title,
postId: Number(position.url.split("/").pop()),
icon: position.icon,
@@ -33,8 +32,9 @@ function getPositionCard(
end: endStr,
endStamp: Number(position.end_time),
},
});
});
};
res.push(card);
}
return res;
}

View File

@@ -5,8 +5,8 @@
*/
import { getUiafStatus } from "../../../utils/UIAF.js";
import TGSqlite from "../index";
import { importUIAFData } from "../sql/updateData";
import TGSqlite from "../index.js";
import { importUIAFData } from "../sql/updateData.js";
/**
* @description 获取成就概况
@@ -15,7 +15,7 @@ import { importUIAFData } from "../sql/updateData";
*/
async function getOverview(): Promise<TGApp.Sqlite.Achievement.Overview> {
const db = await TGSqlite.getDB();
const res = await db.select<TGApp.Sqlite.Achievement.Overview>(
const res = await db.select<TGApp.Sqlite.Achievement.Overview[]>(
"SELECT SUM(totalCount) as total,SUM(finCount) AS fin From AchievementSeries",
);
return res[0];
@@ -29,7 +29,7 @@ async function getOverview(): Promise<TGApp.Sqlite.Achievement.Overview> {
async function getLatestAchiVersion(): Promise<string> {
const db = await TGSqlite.getDB();
type resType = { version: string };
const res = await db.select<resType>(
const res = await db.select<resType[]>(
"SELECT version FROM Achievements ORDER BY version DESC LIMIT 1;",
);
return res[0].version;
@@ -45,11 +45,11 @@ async function getSeries(id?: number): Promise<TGApp.Sqlite.Achievement.SeriesTa
const db = await TGSqlite.getDB();
let res: TGApp.Sqlite.Achievement.SeriesTable[];
if (id === undefined) {
res = await db.select<TGApp.Sqlite.Achievement.SeriesTable>(
res = await db.select<TGApp.Sqlite.Achievement.SeriesTable[]>(
"SELECT * FROM AchievementSeries ORDER BY `order`;",
);
} else {
res = await db.select<TGApp.Sqlite.Achievement.SeriesTable>(
res = await db.select<TGApp.Sqlite.Achievement.SeriesTable[]>(
"SELECT * FROM AchievementSeries WHERE id = ?;",
[id],
);
@@ -67,11 +67,11 @@ async function getAchievements(id?: string): Promise<TGApp.Sqlite.Achievement.Si
const db = await TGSqlite.getDB();
let res: TGApp.Sqlite.Achievement.SingleTable[];
if (id === undefined) {
res = await db.select<TGApp.Sqlite.Achievement.SingleTable>(
res = await db.select<TGApp.Sqlite.Achievement.SingleTable[]>(
"SELECT * FROM Achievements ORDER BY isCompleted,`order`;",
);
} else {
res = await db.select<TGApp.Sqlite.Achievement.SingleTable>(
res = await db.select<TGApp.Sqlite.Achievement.SingleTable[]>(
"SELECT * FROM Achievements WHERE series = ? ORDER BY isCompleted,`order`;",
[id],
);
@@ -88,7 +88,7 @@ async function getAchievements(id?: string): Promise<TGApp.Sqlite.Achievement.Si
async function getSeriesNameCard(id: string): Promise<string> {
const db = await TGSqlite.getDB();
type resType = { nameCard: string };
const res = await db.select<resType>("SELECT nameCard FROM AchievementSeries WHERE id = ?;", [
const res = await db.select<resType[]>("SELECT nameCard FROM AchievementSeries WHERE id = ?;", [
id,
]);
return res[0].nameCard;
@@ -108,12 +108,12 @@ async function searchAchievements(
const versionReg = /^v\d+(\.\d+)?$/;
if (versionReg.test(keyword)) {
const version = keyword.replace("v", "");
return await db.select<TGApp.Sqlite.Achievement.SingleTable>(
return await db.select<TGApp.Sqlite.Achievement.SingleTable[]>(
"SELECT * FROM Achievements WHERE version LIKE ? ORDER BY isCompleted,`order`;",
[`%${version}%`],
);
}
return await db.select<TGApp.Sqlite.Achievement.SingleTable>(
return await db.select<TGApp.Sqlite.Achievement.SingleTable[]>(
"SELECT * FROM Achievements WHERE name LIKE ? OR description LIKE ? ORDER BY isCompleted,`order`;",
[`%${keyword}%`, `%${keyword}%`],
);
@@ -160,9 +160,11 @@ function transDb2Uiaf(data: TGApp.Sqlite.Achievement.SingleTable): TGApp.Plugins
*/
async function getUIAF(): Promise<TGApp.Plugins.UIAF.Achievement[]> {
const db = await TGSqlite.getDB();
const data = await db.select<TGApp.Sqlite.Achievement.SingleTable>("SELECT * FROM Achievements;");
const data = await db.select<TGApp.Sqlite.Achievement.SingleTable[]>(
"SELECT * FROM Achievements;",
);
const res: TGApp.Plugins.UIAF.Achievement[] = [];
for (const item: TGApp.Sqlite.Achievement.SingleTable of data) {
for (const item of data) {
res.push(transDb2Uiaf(item));
}
return res;

View File

@@ -4,7 +4,7 @@
* @since Beta v0.4.5
*/
import TGSqlite from "../index";
import TGSqlite from "../index.js";
/**
* @description 获取单个帖子的收藏信息

View File

@@ -4,7 +4,7 @@
* @since Beta v0.4.9
*/
import minifySql from "../../../utils/minifySql";
import minifySql from "../../../utils/minifySql.js";
/**
* @description 导入UIAF数据-单项
@@ -12,7 +12,7 @@ import minifySql from "../../../utils/minifySql";
* @param {TGApp.Plugins.UIAF.Achievement} data
* @returns {string} sql
*/
export function importUIAFData(data: TGApp.Plugins.UIAF.Achievement): string[] {
export function importUIAFData(data: TGApp.Plugins.UIAF.Achievement): string {
let sql;
const isCompleted = data.status === 2 || data.status === 3;
if (isCompleted) {