mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-11 09:08:14 +08:00
✨ 完成 深渊数据 的备份与恢复
This commit is contained in:
@@ -184,8 +184,8 @@ import { useAchievementsStore } from "../store/modules/achievements";
|
||||
import { useUserStore } from "../store/modules/user";
|
||||
// utils
|
||||
import { backupUiafData, restoreUiafData } from "../utils/UIAF";
|
||||
import { backupCookieData } from "../web/utils/backupData";
|
||||
import { restoreCookieData } from "../web/utils/restoreData";
|
||||
import { backupAbyssData, backupCookieData } from "../web/utils/backupData";
|
||||
import { restoreAbyssData, restoreCookieData } from "../web/utils/restoreData";
|
||||
import TGSqlite from "../plugins/Sqlite";
|
||||
import TGRequest from "../web/request/TGRequest";
|
||||
|
||||
@@ -363,6 +363,8 @@ async function backupData () {
|
||||
await backupUiafData(achievements);
|
||||
const cookie = await TGSqlite.getCookie();
|
||||
await backupCookieData(cookie);
|
||||
const abyss = await TGSqlite.getAbyss();
|
||||
await backupAbyssData(abyss);
|
||||
loading.value = false;
|
||||
snackbarText.value = "数据已备份!";
|
||||
snackbarColor.value = "success";
|
||||
@@ -381,6 +383,10 @@ async function restoreData () {
|
||||
if (!res) {
|
||||
fail.push("Cookie");
|
||||
}
|
||||
res = await restoreAbyssData();
|
||||
if (!res) {
|
||||
fail.push("深渊数据");
|
||||
}
|
||||
if (fail.length > 0) {
|
||||
snackbarText.value = `${fail.join("、")} 恢复失败!`;
|
||||
snackbarColor.value = "error";
|
||||
|
||||
@@ -14,6 +14,7 @@ import { importUIAFData } from "./sql/updateData";
|
||||
import { getUiafStatus } from "../../utils/UIAF";
|
||||
import {
|
||||
insertAbyssData,
|
||||
importAbyssData,
|
||||
insertAppData,
|
||||
insertGameAccountData,
|
||||
insertRecordData,
|
||||
@@ -338,14 +339,34 @@ class Sqlite {
|
||||
* @param {string} uid 游戏 UID
|
||||
* @returns {Promise<TGApp.Game.Abyss.FullData>}
|
||||
*/
|
||||
public async getAbyss (uid: string): Promise<TGApp.Sqlite.Abyss.SingleTable[]> {
|
||||
public async getAbyss (uid?: string): Promise<TGApp.Sqlite.Abyss.SingleTable[]> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
const sql = `SELECT * FROM SpiralAbyss WHERE uid = '${uid}' order by id desc`;
|
||||
let sql;
|
||||
if (uid) {
|
||||
sql = `SELECT * FROM SpiralAbyss WHERE uid = '${uid}' order by id desc`;
|
||||
} else {
|
||||
sql = "SELECT * FROM SpiralAbyss order by uid, id desc";
|
||||
}
|
||||
const res: TGApp.Sqlite.Abyss.SingleTable[] = await db.select(sql);
|
||||
await db.close();
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 恢复深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {TGApp.Sqlite.Abyss.SingleTable[]} data 深渊数据
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async restoreAbyss (data: TGApp.Sqlite.Abyss.SingleTable[]): Promise<void> {
|
||||
const db = await Database.load(this.dbPath);
|
||||
for (const item of data) {
|
||||
const sql = importAbyssData(item);
|
||||
await db.execute(sql);
|
||||
}
|
||||
await db.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 保存战绩数据
|
||||
* @since Alpha v0.2.0
|
||||
|
||||
@@ -176,6 +176,41 @@ export function insertAbyssData (uid: string, data: TGApp.Game.Abyss.FullData):
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 恢复深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {TGApp.Sqlite.Abyss.SingleTable} data 深渊数据
|
||||
* @returns {string} sql
|
||||
*/
|
||||
export function importAbyssData (data: TGApp.Sqlite.Abyss.SingleTable): string {
|
||||
return `
|
||||
INSERT INTO SpiralAbyss (uid, id, startTime, endTime, totalBattleTimes, totalWinTimes,
|
||||
maxFloor, totalStar, isUnlock, revealRank, defeatRank, damageRank,
|
||||
takeDamageRank, normalSkillRank, energySkillRank, floors, updated)
|
||||
VALUES ('${data.uid}', ${data.id}, '${data.startTime}', '${data.endTime}', ${data.totalBattleTimes},
|
||||
${data.totalWinTimes}, '${data.maxFloor}', ${data.totalStar},
|
||||
${data.isUnlock}, '${data.revealRank}', '${data.defeatRank}', '${data.damageRank}',
|
||||
'${data.takeDamageRank}', '${data.normalSkillRank}', '${data.energySkillRank}', '${data.floors}',
|
||||
datetime('now', 'localtime'))
|
||||
ON CONFLICT(uid, id) DO UPDATE
|
||||
SET startTime = '${data.startTime}',
|
||||
endTime = '${data.endTime}',
|
||||
totalBattleTimes = ${data.totalBattleTimes},
|
||||
totalWinTimes = ${data.totalWinTimes},
|
||||
maxFloor = '${data.maxFloor}',
|
||||
totalStar = ${data.totalStar},
|
||||
isUnlock = ${data.isUnlock},
|
||||
revealRank = '${data.revealRank}',
|
||||
defeatRank = '${data.defeatRank}',
|
||||
damageRank = '${data.damageRank}',
|
||||
takeDamageRank = '${data.takeDamageRank}',
|
||||
normalSkillRank = '${data.normalSkillRank}',
|
||||
energySkillRank = '${data.energySkillRank}',
|
||||
floors = '${data.floors}',
|
||||
updated = datetime('now', 'localtime');
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 插入原神战绩数据
|
||||
* @since Alpha v0.2.0
|
||||
|
||||
@@ -18,3 +18,14 @@ export async function backupCookieData (cookie: Record<string, string>): Promise
|
||||
const savePath = `${await path.appLocalDataDir()}\\userData\\cookie.json`;
|
||||
await fs.writeTextFile(savePath, JSON.stringify(cookie, null, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 备份深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @param {TGApp.Sqlite.Abyss.SingleTable[]} abyssData 深渊数据
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function backupAbyssData (abyssData: TGApp.Sqlite.Abyss.SingleTable[]): Promise<void> {
|
||||
const savePath = `${await path.appLocalDataDir()}\\userData\\abyss.json`;
|
||||
await fs.writeTextFile(savePath, JSON.stringify(abyssData, null, 2));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// tauri
|
||||
import { fs, path } from "@tauri-apps/api";
|
||||
// utils
|
||||
import TGSqlite from "../../utils/TGSqlite";
|
||||
import TGSqlite from "../../plugins/Sqlite";
|
||||
|
||||
/**
|
||||
* @description 恢复 Cookie 数据
|
||||
@@ -22,3 +22,16 @@ export async function restoreCookieData (): Promise<boolean> {
|
||||
await TGSqlite.saveAppData("cookie", JSON.stringify(JSON.parse(cookieData)));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 恢复深渊数据
|
||||
* @since Alpha v0.2.0
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
export async function restoreAbyssData (): Promise<boolean> {
|
||||
const abyssPath = `${await path.appLocalDataDir()}\\userData\\abyss.json`;
|
||||
if (!await fs.exists(abyssPath)) return false;
|
||||
const abyssData = await fs.readTextFile(abyssPath);
|
||||
await TGSqlite.restoreAbyss(JSON.parse(abyssData));
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user