mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
@@ -9,6 +9,7 @@ import { exists, mkdir, writeTextFile, readDir, readTextFile } from "@tauri-apps
|
||||
|
||||
import showSnackbar from "../components/func/snackbar.js";
|
||||
import TGSqlite from "../plugins/Sqlite/index.js";
|
||||
import TSUserAbyss from "../plugins/Sqlite/modules/userAbyss.js";
|
||||
import TSUserAchi from "../plugins/Sqlite/modules/userAchi.js";
|
||||
import TSUserGacha from "../plugins/Sqlite/modules/userGacha.js";
|
||||
|
||||
@@ -32,8 +33,7 @@ export async function backUpUserData(dir: string): Promise<void> {
|
||||
const dataCK = await TGSqlite.getCookie();
|
||||
await writeTextFile(`${dir}${path.sep()}cookie.json`, JSON.stringify(dataCK));
|
||||
// 备份深渊数据
|
||||
const dataAbyss = await TGSqlite.getAbyss();
|
||||
await writeTextFile(`${dir}${path.sep()}abyss.json`, JSON.stringify(dataAbyss));
|
||||
await TSUserAbyss.backupAbyss(dir);
|
||||
// 备份祈愿数据
|
||||
const uidList = await TSUserGacha.getUidList();
|
||||
for (const uid of uidList) {
|
||||
@@ -81,22 +81,10 @@ export async function restoreUserData(dir: string): Promise<void> {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1500));
|
||||
}
|
||||
// 恢复深渊数据
|
||||
const abyssFind = files.find((item) => item.name === "abyss.json");
|
||||
if (abyssFind) {
|
||||
try {
|
||||
const dataAbyss: TGApp.Sqlite.Abyss.SingleTable[] = JSON.parse(
|
||||
await readTextFile(abyssFind.name),
|
||||
);
|
||||
await TGSqlite.restoreAbyss(dataAbyss);
|
||||
} catch (e) {
|
||||
await TGLogger.Error(`[DataBS][restoreUserData] 深渊数据恢复失败 ${e}`);
|
||||
showSnackbar({ text: "深渊数据恢复失败", color: "error" });
|
||||
errNum++;
|
||||
}
|
||||
} else {
|
||||
showSnackbar({ text: "深渊数据恢复失败,备份文件不存在", color: "warn" });
|
||||
await TGLogger.Warn(`[DataBS][restoreUserData] 未检测到深渊数据备份文件`);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1500));
|
||||
const restoreAbyss = await TSUserAbyss.restoreAbyss(dir);
|
||||
if (!restoreAbyss) {
|
||||
showSnackbar({ text: "深渊数据恢复失败", color: "error" });
|
||||
errNum++;
|
||||
}
|
||||
// 恢复祈愿数据
|
||||
const reg = /UIGF_(\d+).json/;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file utils/toolFunc.ts
|
||||
* @description 一些工具函数
|
||||
* @since Beta v0.5.0
|
||||
* @since Beta v0.6.0
|
||||
*/
|
||||
|
||||
import { path } from "@tauri-apps/api";
|
||||
@@ -28,35 +28,19 @@ export function stamp2LastTime(time: number): string {
|
||||
|
||||
/**
|
||||
* @description 时间戳转换为日期
|
||||
* @since Alpha v0.2.3
|
||||
* @since Beta v0.6.0
|
||||
* @param {number} timestamp - 时间戳(毫秒)
|
||||
* @returns {string} 日期 2021-01-01 00:00:00
|
||||
*/
|
||||
export function timestampToDate(timestamp: number): string {
|
||||
return new Date(timestamp).toLocaleString("zh", {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取当前时间, YY-MM-DD HH:MM:SS
|
||||
* @since Beta v0.3.6
|
||||
* @returns {string} 当前时间
|
||||
*/
|
||||
export function getNowStr(): string {
|
||||
const now = new Date();
|
||||
const year = now.getFullYear();
|
||||
const month = (now.getMonth() + 1).toString().padStart(2, "0");
|
||||
const date = now.getDate().toString().padStart(2, "0");
|
||||
const hour = now.getHours().toString().padStart(2, "0");
|
||||
const minute = now.getMinutes().toString().padStart(2, "0");
|
||||
const second = now.getSeconds().toString().padStart(2, "0");
|
||||
return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
|
||||
const date = new Date(timestamp);
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(date.getDate()).padStart(2, "0");
|
||||
const hour = String(date.getHours()).padStart(2, "0");
|
||||
const minute = String(date.getMinutes()).padStart(2, "0");
|
||||
const second = String(date.getSeconds()).padStart(2, "0");
|
||||
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user