♻️ 全面整理重构

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

@@ -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