♻️ 全面整理重构

This commit is contained in:
目棃
2024-12-13 16:15:01 +08:00
parent 86bfc80b57
commit 3ed6d503d4
229 changed files with 3105 additions and 4127 deletions

View File

@@ -7,11 +7,6 @@
import getVideoUrl from "./request/getVideoUrl.js";
import getVideoView from "./request/getVideoView.js";
const Bili = {
video: {
view: getVideoView,
url: getVideoUrl,
},
};
const Bili = { video: { view: getVideoView, url: getVideoUrl } };
export default Bili;

View File

@@ -4,7 +4,7 @@
* @since Beta v0.5.0
*/
import TGHttp from "../../../utils/TGHttp.js";
import TGHttp from "@/utils/TGHttp.js";
/**
* @description Bili 插件导航请求

View File

@@ -4,8 +4,9 @@
* @since Beta v0.5.0
*/
import TGHttp from "../../../utils/TGHttp.js";
import getWrid from "../utils/getWrid.js";
import getWrid from "@Bili/utils/getWrid.js";
import TGHttp from "@/utils/TGHttp.js";
/**
* @description 获取视频播放地址

View File

@@ -4,7 +4,7 @@
* @since Beta v0.5.0
*/
import TGHttp from "../../../utils/TGHttp.js";
import TGHttp from "@/utils/TGHttp.js";
/**
* @description 获取视频基本信息

View File

@@ -4,10 +4,9 @@
* @since Beta v0.4.1
*/
import getNav from "@Bili/request/getNav.js";
import md5 from "js-md5";
import getNav from "../request/getNav.js";
/**
* @description 获取 key 值
* @since Beta v0.4.0
@@ -34,9 +33,7 @@ async function getMixinKey(): Promise<string> {
54, 21, 56, 59, 6, 63, 57, 62, 11, 36, 20, 34, 44, 52,
];
const res = [];
for (const i of MIXIN_KEY_ENC_TAB) {
res.push(key[i]);
}
for (const i of MIXIN_KEY_ENC_TAB) res.push(key[i]);
return res.join("").slice(0, 32);
}
@@ -57,11 +54,8 @@ async function getWrid(params: Record<string, string | number>): Promise<[string
let md5Str = "";
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (i === keys.length - 1) {
md5Str += `${key}=${obj[key]}`;
} else {
md5Str += `${key}=${obj[key]}&`;
}
if (i === keys.length - 1) md5Str += `${key}=${obj[key]}`;
else md5Str += `${key}=${obj[key]}&`;
}
const wrid = md5.md5(`${md5Str}${mixin_key}`);
return [wts.toString(), wrid];

View File

@@ -3,9 +3,9 @@
* @description 深渊相关请求
* @since Beta v0.6.3
*/
import TGHttp from "../../../utils/TGHttp.js";
import TGHttp from "@/utils/TGHttp.js";
const AbyssUrl = `https://homa.snapgenshin.com/Statistics/`;
const AbyssUrl: Readonly<string> = `https://homa.snapgenshin.com/Statistics/`;
/**
* @description 获取深渊概览数据

View File

@@ -3,9 +3,9 @@
* @description 幻想真境剧诗相关请求
* @since Beta v0.6.3
*/
import TGHttp from "../../../utils/TGHttp.js";
import TGHttp from "@/utils/TGHttp.js";
const CombatUrl = "https://homa.snapgenshin.com/RoleCombat/";
const CombatUrl: Readonly<string> = "https://homa.snapgenshin.com/RoleCombat/";
/**
* @description 获取数据

View File

@@ -5,9 +5,9 @@
*/
import * as ApiHub from "./request/apiHubReq.js";
import { getCaptcha, doCaptchaLogin } from "./request/doCaptchaLogin.js";
import { doCaptchaLogin, getCaptcha } from "./request/doCaptchaLogin.js";
import { getLoginQr, getLoginStatus } from "./request/doGameLogin.js";
import { getPositionData, getGachaData } from "./request/obcReq.js";
import { getGachaData, getPositionData } from "./request/obcReq.js";
import * as Painter from "./request/painterReq.js";
import * as Post from "./request/postReq.js";
import { getGachaCard } from "./utils/getGachaCard.js";
@@ -18,24 +18,10 @@ const Mys = {
Post,
Painter,
ApiHub,
Gacha: {
get: getGachaData,
card: getGachaCard,
},
Position: {
get: getPositionData,
card: getPositionCard,
},
Lottery: {
get: Painter.lotteryUserShow,
card: getLotteryCard,
},
User: {
getQr: getLoginQr,
getData: getLoginStatus,
getCaptcha,
login: doCaptchaLogin,
},
Gacha: { get: getGachaData, card: getGachaCard },
Position: { get: getPositionData, card: getPositionCard },
Lottery: { get: Painter.lotteryUserShow, card: getLotteryCard },
User: { getQr: getLoginQr, getData: getLoginStatus, getCaptcha, login: doCaptchaLogin },
};
export default Mys;

View File

@@ -4,11 +4,11 @@
* @since Beta v0.6.2
*/
import TGHttp from "../../../utils/TGHttp.js";
import TGHttp from "@/utils/TGHttp.js";
// MysApiHubApiBaseUrl => Mahabu
const Mahabu = "https://bbs-api.miyoushe.com/apihub/api/";
const Referer = "https://bbs.mihoyo.com/";
const Mahabu: Readonly<string> = "https://bbs-api.miyoushe.com/apihub/api/";
const Referer: Readonly<string> = "https://bbs.mihoyo.com/";
/**
* @description 获取投票信息

View File

@@ -4,12 +4,12 @@
* @since Beta v0.5.1
*/
import showSnackbar from "@comp/func/snackbar.js";
import { JSEncrypt } from "jsencrypt";
import showSnackbar from "../../../components/func/snackbar.js";
import TGHttp from "../../../utils/TGHttp.js";
import { getDeviceInfo } from "../../../utils/toolFunc.js";
import TGConstant from "../../../web/constant/TGConstant.js";
import TGHttp from "@/utils/TGHttp.js";
import { getDeviceInfo } from "@/utils/toolFunc.js";
import TGConstant from "@/web/constant/TGConstant.js";
const PUB_KEY_STR: Readonly<string> = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDvekdPMHN3AYhm/vktJT+YJr7cI5DcsNKqdsx5DZX0gDuWFuIjzdwButrIYPNmRJ1G8ybDIF7oDW2eEpm5sMbL9zs

View File

@@ -4,9 +4,9 @@
* @since Beta v0.5.0
*/
import TGHttp from "../../../utils/TGHttp.js";
import { getDeviceInfo } from "../../../utils/toolFunc.js";
import { getRequestHeader } from "../../../web/utils/getRequestHeader.js";
import TGHttp from "@/utils/TGHttp.js";
import { getDeviceInfo } from "@/utils/toolFunc.js";
import { getRequestHeader } from "@/web/utils/getRequestHeader.js";
const APP_ID = 8;

View File

@@ -4,7 +4,7 @@
* @since Beta v0.5.0
*/
import TGHttp from "../../../utils/TGHttp.js";
import TGHttp from "@/utils/TGHttp.js";
/**
* @description 获取表情包列表
@@ -18,10 +18,10 @@ export async function getEmojis(): Promise<Record<string, string> | TGApp.BBS.Re
});
if (resp.retcode !== 0) return <TGApp.BBS.Response.Base>resp;
const emojis: Record<string, string> = {};
resp.data.list.forEach((series) => {
series.list.forEach((emoji) => {
for (const series of resp.data.list) {
for (const emoji of series.list) {
emojis[emoji.name] = emoji.icon;
});
});
}
}
return emojis;
}

View File

@@ -4,9 +4,9 @@
* @since Beta v0.6.3
*/
import TGHttp from "../../../utils/TGHttp.js";
import TGHttp from "@/utils/TGHttp.js";
const obcApi = "https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/";
const obcApi: Readonly<string> = "https://api-takumi.mihoyo.com/common/blackboard/ys_obc/v1/";
/**
* @description 获取卡池信息

View File

@@ -3,10 +3,10 @@
* @description painter下的请求
* @since Beta v0.6.2
*/
import TGHttp from "../../../utils/TGHttp.js";
import TGHttp from "@/utils/TGHttp.js";
// MysPainterApiBaseUrl => Mpabu
const Mpabu = "https://bbs-api.miyoushe.com/painter/wapi/";
const Mpabu: Readonly<string> = "https://bbs-api.miyoushe.com/painter/wapi/";
/**
* @description 获取 News 列表

View File

@@ -4,13 +4,13 @@
* @since Beta v0.6.4
*/
import TGHttp from "../../../utils/TGHttp.js";
import TGHttp from "@/utils/TGHttp.js";
// MysPostApiBaseUrl => Mpabu
const Mpabu = "https://bbs-api.mihoyo.com/post/wapi/";
const Mpabu: Readonly<string> = "https://bbs-api.mihoyo.com/post/wapi/";
// MysTopicApiBaseUrl => Mtapu
const Mtabu = "https://bbs-api.miyoushe.com/topic/wapi/";
const Referer = "https://bbs.mihoyo.com/";
const Mtabu: Readonly<string> = "https://bbs-api.miyoushe.com/topic/wapi/";
const Referer: Readonly<string> = "https://bbs.mihoyo.com/";
/**
* @description 获取特定论坛列表

View File

@@ -1,15 +1,9 @@
/**
* @file plugins/Mys/types/Gacha.d.ts
* @description Mys 插件卡池类型定义文件
* @since Beta v0.4.4
* @since Beta v0.6.6
*/
/**
* @description Mys 卡池类型定义
* @since Beta v0.4.4
* @namespace TGApp.Plugins.Mys.Gacha
* @memberof TGApp.Plugins.Mys
*/
declare namespace TGApp.Plugins.Mys.Gacha {
/**
* @description 获取卡池信息返回
@@ -60,7 +54,7 @@ declare namespace TGApp.Plugins.Mys.Gacha {
/**
* @description 用于渲染的卡池数据
* @since Beta v0.4.4
* @since Beta v0.6.6
* @interface RenderCard
* @property {string} id 卡池ID
* @property {string} title 卡池标题
@@ -71,6 +65,7 @@ declare namespace TGApp.Plugins.Mys.Gacha {
* @property {string} time.str 卡池时间字符串
* @property {string} time.startStamp 卡池开始时间戳
* @property {string} time.endStamp 卡池结束时间戳
* @property {string} time.totalStamp 卡池持续时间戳
* @return RenderCard
*/
interface RenderCard {
@@ -84,6 +79,7 @@ declare namespace TGApp.Plugins.Mys.Gacha {
str: string;
startStamp: number;
endStamp: number;
totalStamp: number;
};
}

View File

@@ -1,15 +1,9 @@
/**
* @file plugins/Mys/types/Position.d.ts
* @description Mys 插件热点追踪接口
* @since Beta v0.5.3
* @since Beta v0.6.6
*/
/**
* @description Mys 插件热点追踪类型
* @since Alpha v0.2.1
* @namespace TGApp.Plugins.Mys.Position
* @memberof TGApp.Plugins.Mys
*/
declare namespace TGApp.Plugins.Mys.Position {
/**
* @description 热点追踪信息的返回类型
@@ -74,7 +68,7 @@ declare namespace TGApp.Plugins.Mys.Position {
/**
* @description 渲染用的热点追踪信息
* @since Beta v0.5.3
* @since Beta v0.6.6
* @interface RenderCard
* @property {string} title 标题
* @property {number} postId 帖子ID
@@ -82,10 +76,9 @@ declare namespace TGApp.Plugins.Mys.Position {
* @property {string} icon 图标
* @property {string} abstract 摘要
* @property time 时间
* @property {string} time.start 开始时间
* @property {number} time.startStamp 开始时间戳
* @property {string} time.end 结束时间
* @property {number} time.endStamp 结束时间戳
* @property {number} time.totalStamp 总时间戳
* @return RenderCard
*/
interface RenderCard {
@@ -95,10 +88,9 @@ declare namespace TGApp.Plugins.Mys.Position {
icon: string;
abstract: string;
time: {
start: string;
startStamp: number;
end: string;
endStamp: number;
totalStamp: number;
};
}
}

View File

@@ -4,13 +4,14 @@
* @since Beta v0.6.3
*/
import showSnackbar from "../../../components/func/snackbar.js";
import { AppCharacterData } from "../../../data/index.js";
import { getPostFull } from "../request/postReq.js";
import showSnackbar from "@comp/func/snackbar.js";
import { getPostFull } from "@Mys/request/postReq.js";
import { AppCharacterData } from "@/data/index.js";
/**
* @description 根据单个卡池信息转为渲染用的卡池信息
* @since Beta v0.6.3
* @since Beta v0.6.6
* @param {TGApp.Plugins.Mys.Gacha.Data} data 卡池信息
* @param {string} poolCover 卡池封面
* @returns {Promise<TGApp.Plugins.Mys.Gacha.RenderCard>}
@@ -54,6 +55,7 @@ async function getGachaItemCard(
str: timeStr,
startStamp: new Date(data.start_time).getTime(),
endStamp: new Date(data.end_time).getTime(),
totalStamp: new Date(data.end_time).getTime() - new Date(data.start_time).getTime(),
},
};
}
@@ -70,11 +72,9 @@ export async function getGachaCard(
poolCover?: Record<number, string>,
): Promise<TGApp.Plugins.Mys.Gacha.RenderCard[]> {
const gachaCard: TGApp.Plugins.Mys.Gacha.RenderCard[] = [];
await Promise.allSettled(
gachaData.map(async (data: TGApp.Plugins.Mys.Gacha.Data) => {
const item = await getGachaItemCard(data, poolCover?.[Number(data.id)]);
if (item !== null) gachaCard.push(item);
}),
);
for (const data of gachaData) {
const item = await getGachaItemCard(data, poolCover?.[Number(data.id)]);
if (item !== null) gachaCard.push(item);
}
return gachaCard;
}

View File

@@ -37,9 +37,7 @@ function getLotteryCard(
status: lotteryData.status,
creator: lotteryData.creator,
drawTime: lotteryData.draw_time,
rewards: lotteryData.user_rewards.map((reward) => {
return getLotteryRewardCard(reward);
}),
rewards: lotteryData.user_rewards.map(getLotteryRewardCard),
};
}

View File

@@ -1,12 +1,12 @@
/**
* @file plugins/Mys/utils/getPositionCard.ts
* @description Mys 插件热点追踪工具
* @since Beta v0.6.2
* @since Beta v0.6.6
*/
/**
* @description 根据热点追踪信息转为渲染用的数据
* @since Beta v0.6.2
* @since Beta v0.6.6
* @param {TGApp.Plugins.Mys.Position.Data[]} positionData 列表
* @returns {TGApp.Plugins.Mys.Position.RenderCard[]} 返回列表
*/
@@ -15,28 +15,19 @@ function getPositionCard(
): TGApp.Plugins.Mys.Position.RenderCard[] {
const res: TGApp.Plugins.Mys.Position.RenderCard[] = [];
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, "-");
}
let link = position.url;
if (position.url === "" && position.content_id !== 0) {
link = `https://bbs.mihoyo.com/ys/obc/content/${position.content_id}/detail?bbs_presentation_style=no_header`;
}
const startTs = new Date(position.create_time).getTime();
const endTs = Number(position.end_time);
const card: TGApp.Plugins.Mys.Position.RenderCard = {
title: position.title,
postId: position.url !== "" ? Number(position.url.split("/").pop()) : position.content_id,
link: link,
icon: position.icon,
abstract: position.abstract,
time: {
start: position.create_time.split(" ")[0].replace(/\//g, "-"),
startStamp: new Date(position.create_time).getTime(),
end: endStr,
endStamp: Number(position.end_time),
},
time: { startStamp: startTs, endStamp: endTs, totalStamp: endTs - startTs },
};
res.push(card);
}

View File

@@ -7,24 +7,14 @@
import { app } from "@tauri-apps/api";
import Database from "@tauri-apps/plugin-sql";
import TGLogger from "../../utils/TGLogger.js";
import initDataSql from "./sql/initData.js";
import { insertAppData } from "./sql/insertData.js";
import TGLogger from "@/utils/TGLogger.js";
class Sqlite {
/**
* @description 数据库地址
* @since Alpha v0.2.0
* @private
*/
private readonly dbPath: string = "sqlite:TeyvatGuide.db";
/**
* @description 数据库包含的表
* @since Beta v0.6.0
* @private
*/
private readonly tables: string[] = [
private readonly tables: Readonly<Array<string>> = [
"Achievements",
"AppData",
"GachaRecords",
@@ -37,13 +27,15 @@ class Sqlite {
"UserCharacters",
"UserRecord",
];
/**
* @description 内部数据库实例
* @since Beta v0.3.3
* @private
*/
private db: Database | null = null;
private static instance: Sqlite | null = null;
static getInstance(): Sqlite {
if (this.instance === null) this.instance = new Sqlite();
return this.instance;
}
private constructor() {}
/**
* @description 获取数据库实例
@@ -51,9 +43,7 @@ class Sqlite {
* @returns {Promise<Database>}
*/
public async getDB(): Promise<Database> {
if (this.db === null) {
this.db = await Database.load(this.dbPath);
}
if (this.db === null) this.db = await Database.load(this.dbPath);
return this.db;
}
@@ -86,9 +76,7 @@ class Sqlite {
public async initDB(): Promise<void> {
const db = await this.getDB();
const sql = await initDataSql();
for (const item of sql) {
await db.execute(item);
}
for (const item of sql) await db.execute(item);
}
/**
@@ -136,9 +124,7 @@ class Sqlite {
public async update(): Promise<void> {
const db = await this.getDB();
const sqlD = await initDataSql();
for (const item of sqlD) {
await db.execute(item);
}
for (const item of sqlD) await db.execute(item);
// 检测是否存在字段
await this.updateAbyss();
}
@@ -166,16 +152,14 @@ class Sqlite {
*/
public async reset(): Promise<void> {
const db = await this.getDB();
await Promise.all(
this.tables.map(async (item) => {
const sql = `DROP TABLE IF EXISTS ${item};`;
await db.execute(sql);
}),
);
for (const item of this.tables) {
const sql = `DROP TABLE IF EXISTS ${item};`;
await db.execute(sql);
}
await this.initDB();
}
}
const TGSqlite = new Sqlite();
const TGSqlite = Sqlite.getInstance();
export default TGSqlite;

View File

@@ -4,7 +4,7 @@
* @since Beta v0.4.6
*/
import { AppCharacterData, ArcBirCalendar, ArcBirRole } from "../../../data/index.js";
import { AppCharacterData, ArcBirCalendar, ArcBirRole } from "@/data/index.js";
/**
* @description 判断今天是不是角色生日
@@ -18,21 +18,17 @@ function isAvatarBirth(): TGApp.Archive.Birth.CalendarItem[] {
const days = ArcBirCalendar[month];
const find = days.filter((i) => i.role_birthday === `${month}/${day}`);
if (find.length > 0) {
return find.map((i) => {
i.is_subscribe = true;
return i;
});
for (const i of find) i.is_subscribe = true;
return find;
}
const find2 = AppCharacterData.filter((i) => i.birthday.toString() === [month, day].toString());
return find2.map((i) => {
return <TGApp.Archive.Birth.CalendarItem>{
role_id: i.id,
name: i.name,
role_birthday: `${month}/${day}`,
head_icon: `/WIKI/character/${i.id}.webp`,
is_subscribe: false,
};
});
return find2.map((i) => ({
role_id: i.id,
name: i.name,
role_birthday: `${month}/${day}`,
head_icon: `/WIKI/character/${i.id}.webp`,
is_subscribe: false,
}));
}
/**
@@ -68,9 +64,7 @@ function getNextAvatarBirth(date?: [number, number]): TGApp.Archive.Birth.RoleIt
const roleBirth = getRoleBirth(item.role_birthday);
if (roleBirth[0] < month || (roleBirth[0] === month && roleBirth[1] <= day)) {
birthDateList.push(new Date(year + 1, roleBirth[0] - 1, roleBirth[1]));
} else {
birthDateList.push(new Date(year, roleBirth[0] - 1, roleBirth[1]));
}
} else birthDateList.push(new Date(year, roleBirth[0] - 1, roleBirth[1]));
}
birthDateList.sort((a, b) => a.getTime() - b.getTime());
const nextDateGet = birthDateList[0];
@@ -78,9 +72,6 @@ function getNextAvatarBirth(date?: [number, number]): TGApp.Archive.Birth.RoleIt
return ArcBirRole.filter((i) => i.role_birthday === `${nextDate[0]}/${nextDate[1]}`);
}
const TSAvatarBirth = {
isAvatarBirth,
getNextAvatarBirth,
};
const TSAvatarBirth = { isAvatarBirth, getNextAvatarBirth };
export default TSAvatarBirth;

View File

@@ -4,13 +4,13 @@
* @since Beta v0.6.1
*/
import TGSqlite from "@Sqlite/index.js";
import { transCharacterData, transFloorData } from "@Sqlite/utils/transAbyssData.js";
import { path } from "@tauri-apps/api";
import { exists, mkdir, readTextFile, writeTextFile } from "@tauri-apps/plugin-fs";
import TGLogger from "../../../utils/TGLogger.js";
import { timestampToDate } from "../../../utils/toolFunc.js";
import TGSqlite from "../index.js";
import { transCharacterData, transFloorData } from "../utils/transAbyssData.js";
import TGLogger from "@/utils/TGLogger.js";
import { timestampToDate } from "@/utils/toolFunc.js";
/**
* @description 直接插入数据

View File

@@ -4,12 +4,12 @@
* @since Beta v0.6.1
*/
import TGSqlite from "@Sqlite/index.js";
import { path } from "@tauri-apps/api";
import { exists, mkdir, readTextFile, writeTextFile } from "@tauri-apps/plugin-fs";
import TGLogger from "../../../utils/TGLogger.js";
import { timestampToDate } from "../../../utils/toolFunc.js";
import TGSqlite from "../index.js";
import TGLogger from "@/utils/TGLogger.js";
import { timestampToDate } from "@/utils/toolFunc.js";
/**
* @description 获取插入游戏账号数据的sql
@@ -94,7 +94,7 @@ function transUser(data: TGApp.App.Account.User): TGApp.Sqlite.Account.User {
async function getAllAccount(): Promise<TGApp.App.Account.User[]> {
const db = await TGSqlite.getDB();
const res = await db.select<TGApp.Sqlite.Account.User[]>("SELECT * FROM UserAccount;");
return res.map((account) => parseUser(account));
return res.map(parseUser);
}
/**

View File

@@ -4,13 +4,13 @@
* @since Beta v0.6.0
*/
import TGSqlite from "@Sqlite/index.js";
import { path } from "@tauri-apps/api";
import { exists, mkdir, readDir, readTextFile, writeTextFile } from "@tauri-apps/plugin-fs";
import { AppAchievementsData, AppAchievementSeriesData } from "../../../data/index.js";
import TGLogger from "../../../utils/TGLogger.js";
import { timestampToDate } from "../../../utils/toolFunc.js";
import TGSqlite from "../index.js";
import { AppAchievementsData, AppAchievementSeriesData } from "@/data/index.js";
import TGLogger from "@/utils/TGLogger.js";
import { timestampToDate } from "@/utils/toolFunc.js";
/**
* @description 根据 completed 跟 progress 获取 status
@@ -20,15 +20,10 @@ import TGSqlite from "../index.js";
* @returns {number} status
*/
function getUiafStatus(completed: boolean, progress: number): number {
if (progress !== 0 && !completed) {
return 1;
} else if (progress === 0 && completed) {
return 2;
} else if (progress !== 0 && completed) {
return 3;
} else {
return 0;
}
if (progress !== 0 && !completed) return 1;
if (progress === 0 && completed) return 2;
if (progress !== 0 && completed) return 3;
return 0;
}
/**
@@ -57,11 +52,8 @@ async function getOverview(
): Promise<TGApp.Sqlite.Achievement.Overview> {
const db = await TGSqlite.getDB();
let totalAchi: number[] = [];
if (series === undefined) {
totalAchi = AppAchievementsData.map((i) => i.id);
} else {
totalAchi = AppAchievementsData.filter((s) => s.series === series).map((i) => i.id);
}
if (series === undefined) totalAchi = AppAchievementsData.map((i) => i.id);
else totalAchi = AppAchievementsData.filter((s) => s.series === series).map((i) => i.id);
const finAchi = (
await db.select<TGApp.Sqlite.Achievement.TableAchi[]>(
"SELECT * FROM Achievements WHERE uid = ? AND isCompleted = 1;",
@@ -235,12 +227,7 @@ function transDb2Uiaf(data: TGApp.Sqlite.Achievement.TableAchi): TGApp.Plugins.U
let timestamp = 0;
if (data.isCompleted === 1) timestamp = Math.floor(new Date(data.completedTime).getTime() / 1000);
const status = getUiafStatus(data.isCompleted === 1, data.progress);
return {
id: data.id,
timestamp: timestamp,
current: data.progress,
status,
};
return { id: data.id, timestamp: timestamp, current: data.progress, status };
}
/**
@@ -256,9 +243,7 @@ async function getUiafData(uid: number): Promise<TGApp.Plugins.UIAF.Achievement[
[uid],
);
const res: TGApp.Plugins.UIAF.Achievement[] = [];
for (const item of data) {
res.push(transDb2Uiaf(item));
}
for (const item of data) res.push(transDb2Uiaf(item));
return res;
}

View File

@@ -4,9 +4,10 @@
* @since Beta v0.6.0
*/
import { AppCharacterData } from "../../../data/index.js";
import { timestampToDate } from "../../../utils/toolFunc.js";
import TGSqlite from "../index.js";
import TGSqlite from "@Sqlite/index.js";
import { AppCharacterData } from "@/data/index.js";
import { timestampToDate } from "@/utils/toolFunc.js";
/**
* @description 获取角色插入Sql
@@ -102,9 +103,7 @@ async function getAvatars(uid: number): Promise<TGApp.Sqlite.Character.UserRole[
*/
async function saveAvatars(uid: string, data: TGApp.Game.Avatar.DetailList[]): Promise<void> {
const db = await TGSqlite.getDB();
for (const role of data) {
await db.execute(getInsertSql(uid, role));
}
for (const role of data) await db.execute(getInsertSql(uid, role));
}
/**

View File

@@ -4,7 +4,7 @@
* @since Beta v0.5.5
*/
import TGSqlite from "../index.js";
import TGSqlite from "@Sqlite/index.js";
/**
* @description 获取单个帖子的收藏信息
@@ -18,9 +18,7 @@ async function getPostCollect(
const db = await TGSqlite.getDB();
const sql = "SELECT * FROM UFMap WHERE postId = ?";
const res: TGApp.Sqlite.UserCollection.UFMap[] = await db.select(sql, [postId]);
if (res.length > 0) {
return res;
}
if (res.length > 0) return res;
const unclassifiedSql = "SELECT * FROM UFPost WHERE id = ?";
const unclassifiedRes: TGApp.Sqlite.UserCollection.UFPost[] = await db.select(unclassifiedSql, [
postId,
@@ -83,9 +81,7 @@ async function createCollect(title: string, desc: string): Promise<boolean> {
const db = await TGSqlite.getDB();
const sql = "SELECT id FROM UFCollection WHERE title = ?";
const res: Array<{ id: number }> = await db.select(sql, [title]);
if (res.length > 0) {
return false;
}
if (res.length > 0) return false;
const insertSql = "INSERT INTO UFCollection (title, desc,updated) VALUES (?, ?,?)";
await db.execute(insertSql, [title, desc, new Date().getTime()]);
return true;
@@ -102,9 +98,7 @@ async function deleteCollect(title: string, force: boolean): Promise<boolean> {
const db = await TGSqlite.getDB();
const sql = "SELECT id FROM UFCollection WHERE title = ?";
const res: Array<{ id: number }> = await db.select(sql, [title]);
if (res.length === 0) {
return false;
}
if (res.length === 0) return false;
if (force) {
const deleteSql = "DELETE FROM UFCollection WHERE title = ?";
await db.execute(deleteSql, [title]);
@@ -141,9 +135,7 @@ async function updateCollect(title: string, newTitle: string, newDesc: string):
const db = await TGSqlite.getDB();
const sql = "SELECT id FROM UFCollection WHERE title = ?";
const res: Array<{ id: number }> = await db.select(sql, [title]);
if (res.length === 0) {
return false;
}
if (res.length === 0) return false;
const updateSql = "UPDATE UFCollection SET title = ?, desc = ?, updated = ? WHERE id = ?";
await db.execute(updateSql, [newTitle, newDesc, new Date().getTime(), res[0].id]);
const updateRefSql = "UPDATE UFMap SET collection = ?,desc=?,updated=? WHERE collectionId = ?";
@@ -169,9 +161,8 @@ async function addCollect(
const db = await TGSqlite.getDB();
const sql = "SELECT id FROM UFPost WHERE id = ?";
const res: Array<{ id: number }> = await db.select(sql, [postId]);
if (res.length > 0) {
await updatePostInfo(postId, post);
} else {
if (res.length > 0) await updatePostInfo(postId, post);
else {
const insertSql = "INSERT INTO UFPost (id, title, content, updated) VALUES (?, ?, ?, ?)";
await db.execute(insertSql, [
postId,
@@ -186,13 +177,9 @@ async function addCollect(
collection,
]);
if (collectionRes.length === 0) {
if (!recursive) {
return false;
}
if (!recursive) return false;
const createCollectionRes = await createCollect(collection, collection);
if (!createCollectionRes) {
return false;
}
if (!createCollectionRes) return false;
collectionRes = await db.select(collectionSql, [collection]);
}
// 查找是否已经有了数据
@@ -242,9 +229,7 @@ async function updatePostInfo(
const db = await TGSqlite.getDB();
const sql = "SELECT id FROM UFPost WHERE id = ?";
const res: Array<{ id: number }> = await db.select(sql, [postId]);
if (res.length === 0) {
return false;
}
if (res.length === 0) return false;
const updateSql = "UPDATE UFPost SET title = ?, content = ?, updated = ? WHERE id = ?";
await db.execute(updateSql, [
post.post.subject,
@@ -266,14 +251,10 @@ async function deletePostCollect(postId: string, force: boolean = false): Promis
const db = await TGSqlite.getDB();
const sql = "SELECT id FROM UFPost WHERE id = ?";
const res: Array<{ id: number }> = await db.select(sql, [postId]);
if (res.length === 0) {
return false;
}
if (res.length === 0) return false;
const selectSql = "SELECT * FROM UFMap WHERE postId = ?";
const selectRes: TGApp.Sqlite.UserCollection.UFMap[] = await db.select(selectSql, [postId]);
if (selectRes.length === 0 && !force) {
return false;
}
if (selectRes.length === 0 && !force) return false;
if (force) {
const deletePostSql = "DELETE FROM UFPost WHERE id = ?";
await db.execute(deletePostSql, [postId]);
@@ -294,9 +275,7 @@ async function updatePostCollect(postId: string, collections: string[]): Promise
const db = await TGSqlite.getDB();
const sql = "SELECT id,title FROM UFPost WHERE id = ?";
const res: Array<{ id: number; title: string }> = await db.select(sql, [postId]);
if (res.length === 0) {
return false;
}
if (res.length === 0) return false;
const deleteSql = "DELETE FROM UFMap WHERE postId = ?";
await db.execute(deleteSql, [postId]);
for (let i = 0; i < collections.length; i++) {
@@ -305,9 +284,7 @@ async function updatePostCollect(postId: string, collections: string[]): Promise
collectionSql,
[collections[i]],
);
if (collectionRes.length === 0) {
return false;
}
if (collectionRes.length === 0) return false;
const insertSql =
"INSERT INTO UFMap (postId, collectionId,post, collection, desc, updated) VALUES (?, ?, ?, ?, ?, ?)";
await db.execute(insertSql, [
@@ -340,15 +317,11 @@ async function updatePostsCollect(
const collectionRes: TGApp.Sqlite.UserCollection.UFCollection[] = await db.select(collectionSql, [
collection,
]);
if (collectionRes.length === 0) {
return false;
}
if (collectionRes.length === 0) return false;
for (let i = 0; i < postIds.length; i++) {
const postSql = "SELECT id,title FROM UFPost WHERE id = ?";
const postRes: Array<{ id: number; title: string }> = await db.select(postSql, [postIds[i]]);
if (postRes.length === 0) {
return false;
}
if (postRes.length === 0) return false;
const unclassifiedSql = "SELECT * FROM UFMap where postId = ?";
const unclassifiedRes: TGApp.Sqlite.UserCollection.UFMap[] = await db.select(unclassifiedSql, [
postIds[i],

View File

@@ -4,30 +4,13 @@
* @since Beta v0.6.3
*/
import TGSqlite from "@Sqlite/index.js";
import { transUserCombat } from "@Sqlite/utils/transUserCombat.js";
import { path } from "@tauri-apps/api";
import { exists, mkdir, readTextFile, writeTextFile } from "@tauri-apps/plugin-fs";
import TGLogger from "../../../utils/TGLogger.js";
import { timestampToDate } from "../../../utils/toolFunc.js";
import TGSqlite from "../index.js";
import { transUserCombat } from "../utils/transUserCombat.js";
/**
* @description 数据表检测
* @since Beta v0.6.3
* @todo 版更后移除,该方法仅用于测试版过渡
* @return {Promise<boolean>}
*/
async function check(): Promise<boolean> {
const db = await TGSqlite.getDB();
try {
await db.select("SELECT DISTINCT uid FROM RoleCombat;");
return true;
} catch (e) {
console.log(e);
return false;
}
}
import TGLogger from "@/utils/TGLogger.js";
import { timestampToDate } from "@/utils/toolFunc.js";
/**
* @description 直接插入数据
@@ -153,9 +136,7 @@ async function restoreCombat(dir: string): Promise<boolean> {
try {
const data: TGApp.Sqlite.Combat.SingleTable[] = JSON.parse(await readTextFile(filePath));
const db = await TGSqlite.getDB();
for (const abyss of data) {
await db.execute(getInsertSql(abyss));
}
for (const abyss of data) await db.execute(getInsertSql(abyss));
return true;
} catch (e) {
await TGLogger.Error(`恢复剧诗数据失败${filePath}`);
@@ -165,7 +146,6 @@ async function restoreCombat(dir: string): Promise<boolean> {
}
const TSUserCombat = {
check,
getAllUid,
getCombat,
saveCombat,

View File

@@ -4,14 +4,14 @@
* @since Beta v0.6.0
*/
import showSnackbar from "@comp/func/snackbar.js";
import TGSqlite from "@Sqlite/index.js";
import { path } from "@tauri-apps/api";
import { exists, mkdir, readDir } from "@tauri-apps/plugin-fs";
import showSnackbar from "../../../components/func/snackbar.js";
import { AppCharacterData, AppWeaponData } from "../../../data/index.js";
import TGLogger from "../../../utils/TGLogger.js";
import { exportUigfData, readUigfData, verifyUigfData } from "../../../utils/UIGF.js";
import TGSqlite from "../index.js";
import { AppCharacterData, AppWeaponData } from "@/data/index.js";
import TGLogger from "@/utils/TGLogger.js";
import { exportUigfData, readUigfData, verifyUigfData } from "@/utils/UIGF.js";
type gachaItemTypeRes =
| ["角色", TGApp.App.Character.WikiBriefInfo]
@@ -44,19 +44,19 @@ function getInsertSql(uid: string, gacha: TGApp.Plugins.UIGF.GachaItem): string
INSERT INTO GachaRecords (uid, gachaType, itemId, count, time, name, type, rank, id, uigfType, updated)
VALUES ('${uid}', '${gacha.gacha_type}', '${gacha.item_id ?? null}', '${gacha.count ?? null}', '${gacha.time}',
'${gacha.name}', '${gacha.item_type ?? null}', '${gacha.rank_type ?? null}', '${gacha.id}',
'${gacha.uigf_gacha_type}', datetime('now', 'localtime'))
ON CONFLICT (id)
DO UPDATE
SET uid = '${uid}',
gachaType = '${gacha.gacha_type}',
uigfType = '${gacha.uigf_gacha_type}',
time = '${gacha.time}',
itemId = '${gacha.item_id ?? null}',
count = '${gacha.count ?? null}',
name = '${gacha.name}',
type = '${gacha.item_type ?? null}',
rank = '${gacha.rank_type ?? null}',
updated = datetime('now', 'localtime');
'${gacha.uigf_gacha_type}', datetime('now', 'localtime')) ON CONFLICT (id)
DO
UPDATE
SET uid = '${uid}',
gachaType = '${gacha.gacha_type}',
uigfType = '${gacha.uigf_gacha_type}',
time = '${gacha.time}',
itemId = '${gacha.item_id ?? null}',
count = '${gacha.count ?? null}',
name = '${gacha.name}',
type = '${gacha.item_type ?? null}',
rank = '${gacha.rank_type ?? null}',
updated = datetime('now', 'localtime');
`;
}

View File

@@ -4,9 +4,10 @@
* @since Beta v0.6.0
*/
import { timestampToDate } from "../../../utils/toolFunc.js";
import TGSqlite from "../index.js";
import { transUserRecord } from "../utils/transUserRecord.js";
import TGSqlite from "@Sqlite/index.js";
import { transUserRecord } from "@Sqlite/utils/transUserRecord.js";
import { timestampToDate } from "@/utils/toolFunc.js";
/**
* @description 获取插入Sql

View File

@@ -6,10 +6,10 @@
import { app } from "@tauri-apps/api";
import { getBuildTime } from "../../../utils/TGBuild.js";
import initTableSql from "./initTable.js";
import { getBuildTime } from "@/utils/TGBuild.js";
/**
* @description 初始化应用表数据
* @since Alpha v0.2.2

View File

@@ -4,7 +4,7 @@
* @since Beta v0.6.0
*/
import { timestampToDate } from "../../../utils/toolFunc.js";
import { timestampToDate } from "@/utils/toolFunc.js";
/**
* @description 将通过 api 获取到的深渊数据转换为数据库中的数据
@@ -13,13 +13,11 @@ import { timestampToDate } from "../../../utils/toolFunc.js";
* @returns {string} 转换后的深渊数据
*/
export function transCharacterData(data: TGApp.Game.Abyss.CharacterData[]): string {
const res: TGApp.Sqlite.Abyss.Character[] = data.map((item) => {
return {
id: item.avatar_id,
value: item.value,
star: item.rarity,
};
});
const res: TGApp.Sqlite.Abyss.Character[] = data.map((item) => ({
id: item.avatar_id,
value: item.value,
star: item.rarity,
}));
return JSON.stringify(res);
}
@@ -30,15 +28,13 @@ export function transCharacterData(data: TGApp.Game.Abyss.CharacterData[]): stri
* @returns {string} 转换后的深渊数据
*/
export function transFloorData(data: TGApp.Game.Abyss.Floor[]): string {
const floor: TGApp.Sqlite.Abyss.Floor[] = data.map((item) => {
return {
id: item.index,
winStar: item.star,
maxStar: item.max_star,
isUnlock: item.is_unlock ? 1 : 0,
levels: item.levels.map((level) => transLevelData(level)),
};
});
const floor: TGApp.Sqlite.Abyss.Floor[] = data.map((item) => ({
id: item.index,
winStar: item.star,
maxStar: item.max_star,
isUnlock: item.is_unlock ? 1 : 0,
levels: item.levels.map((level) => transLevelData(level)),
}));
return JSON.stringify(floor);
}
@@ -55,11 +51,8 @@ function transLevelData(data: TGApp.Game.Abyss.Level): TGApp.Sqlite.Abyss.Level
maxStar: data.max_star,
};
for (const battle of data.battles) {
if (battle.index === 1) {
res.upBattle = transBattleData(battle);
} else {
res.downBattle = transBattleData(battle);
}
if (battle.index === 1) res.upBattle = transBattleData(battle);
else res.downBattle = transBattleData(battle);
}
return res;
}
@@ -73,12 +66,10 @@ function transLevelData(data: TGApp.Game.Abyss.Level): TGApp.Sqlite.Abyss.Level
function transBattleData(data: TGApp.Game.Abyss.Battle): TGApp.Sqlite.Abyss.Battle {
return {
time: timestampToDate(Number(data.timestamp) * 1000),
characters: data.avatars.map((item) => {
return {
id: item.id,
level: item.level,
star: item.rarity,
};
}),
characters: data.avatars.map((item) => ({
id: item.id,
level: item.level,
star: item.rarity,
})),
};
}

View File

@@ -4,7 +4,7 @@
* @since Beta v0.6.3
*/
import { timestampToDate } from "../../../utils/toolFunc.js";
import { timestampToDate } from "@/utils/toolFunc.js";
/**
* @description 将通过 api 获取到的数据转换为数据库中的数据

View File

@@ -4,7 +4,7 @@
* @since Beta v0.6.0
*/
import { getZhElement } from "../../../utils/toolFunc.js";
import { getZhElement } from "@/utils/toolFunc.js";
/**
* @description 将通过 api 获取到的用户战绩数据转换为渲染用的数据
@@ -114,9 +114,7 @@ function transWorld(data: TGApp.Game.Record.WorldExplore[]): TGApp.Sqlite.Record
exploration: area.exploration_percentage,
children: [],
};
if (area.type === "Reputation") {
world.reputation = area.level;
}
if (area.type === "Reputation") world.reputation = area.level;
if (area.offerings !== undefined && area.offerings.length > 0) {
world.offering = {
name: area.offerings[0].name,
@@ -134,13 +132,13 @@ function transWorld(data: TGApp.Game.Record.WorldExplore[]): TGApp.Sqlite.Record
"https://fastcdn.mihoyo.com/static-resource-v2/2024/08/19/8856eafed39be791276a21a6d522426b_6903333123294722705.png";
}
const children = areaChild.filter((i) => i.parent_id === area.id);
children.map((child) => {
return world.children.push({
for (const child of children) {
world.children.push({
id: child.id,
name: child.name,
exploration: child.exploration_percentage,
});
});
}
worlds.push(world);
}
return worlds;