mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-09 08:48:21 +08:00
👽️ 全量刷新时清理旧数据
This commit is contained in:
@@ -52,7 +52,7 @@
|
|||||||
import { path } from "@tauri-apps/api";
|
import { path } from "@tauri-apps/api";
|
||||||
import { open, save } from "@tauri-apps/plugin-dialog";
|
import { open, save } from "@tauri-apps/plugin-dialog";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { onMounted, ref, watch, computed } from "vue";
|
import { computed, onMounted, ref, watch } from "vue";
|
||||||
|
|
||||||
import showDialog from "../../components/func/dialog.js";
|
import showDialog from "../../components/func/dialog.js";
|
||||||
import showLoading from "../../components/func/loading.js";
|
import showLoading from "../../components/func/loading.js";
|
||||||
@@ -66,11 +66,11 @@ import TSUserGacha from "../../plugins/Sqlite/modules/userGacha.js";
|
|||||||
import { useUserStore } from "../../store/modules/user.js";
|
import { useUserStore } from "../../store/modules/user.js";
|
||||||
import TGLogger from "../../utils/TGLogger.js";
|
import TGLogger from "../../utils/TGLogger.js";
|
||||||
import {
|
import {
|
||||||
|
exportUigf4Data,
|
||||||
exportUigfData,
|
exportUigfData,
|
||||||
readUigf4Data,
|
readUigf4Data,
|
||||||
readUigfData,
|
readUigfData,
|
||||||
verifyUigfData,
|
verifyUigfData,
|
||||||
exportUigf4Data,
|
|
||||||
} from "../../utils/UIGF.js";
|
} from "../../utils/UIGF.js";
|
||||||
import Hk4eApi from "../../web/request/hk4eReq.js";
|
import Hk4eApi from "../../web/request/hk4eReq.js";
|
||||||
import TakumiApi from "../../web/request/takumiReq.js";
|
import TakumiApi from "../../web/request/takumiReq.js";
|
||||||
@@ -161,66 +161,57 @@ async function confirmRefresh(force: boolean): Promise<void> {
|
|||||||
showLoading.end();
|
showLoading.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let checkList: Array<string | undefined> = [
|
await refreshGachaPool("100", "新手祈愿", force);
|
||||||
undefined,
|
await refreshGachaPool("200", "常驻祈愿", force);
|
||||||
undefined,
|
await refreshGachaPool("301", "角色祈愿", force);
|
||||||
undefined,
|
await refreshGachaPool("400", "角色祈愿2", force);
|
||||||
undefined,
|
await refreshGachaPool("302", "武器祈愿", force);
|
||||||
undefined,
|
await refreshGachaPool("500", "集录祈愿", force);
|
||||||
];
|
|
||||||
if (!force) {
|
|
||||||
showLoading.update("正在刷新祈愿数据", "正在获取数据库祈愿最新 ID");
|
|
||||||
checkList[0] = await TSUserGacha.getGachaCheck(account.value.gameUid, "200");
|
|
||||||
checkList[1] = await TSUserGacha.getGachaCheck(account.value.gameUid, "301");
|
|
||||||
checkList[2] = await TSUserGacha.getGachaCheck(account.value.gameUid, "400");
|
|
||||||
checkList[3] = await TSUserGacha.getGachaCheck(account.value.gameUid, "302");
|
|
||||||
checkList[4] = await TSUserGacha.getGachaCheck(account.value.gameUid, "500");
|
|
||||||
}
|
|
||||||
console.log(checkList);
|
|
||||||
showLoading.update("正在刷新新手祈愿数据");
|
|
||||||
await getGachaLogs("100", "0", "新手祈愿", undefined);
|
|
||||||
showLoading.update("正在刷新常驻祈愿数据");
|
|
||||||
await getGachaLogs("200", "0", "常驻祈愿", checkList[0]);
|
|
||||||
showLoading.update("正在刷新角色祈愿数据");
|
|
||||||
await getGachaLogs("301", "0", "角色祈愿", checkList[1]);
|
|
||||||
showLoading.update("正在刷新角色祈愿2数据");
|
|
||||||
await getGachaLogs("400", "0", "角色祈愿2", checkList[2]);
|
|
||||||
showLoading.update("正在刷新武器祈愿数据");
|
|
||||||
await getGachaLogs("302", "0", "武器祈愿", checkList[3]);
|
|
||||||
showLoading.update("正在刷新集录祈愿数据");
|
|
||||||
await getGachaLogs("500", "0", "集录祈愿", checkList[4]);
|
|
||||||
showLoading.update("正在刷新祈愿数据", "数据获取完成,即将刷新页面");
|
showLoading.update("正在刷新祈愿数据", "数据获取完成,即将刷新页面");
|
||||||
showLoading.end();
|
showLoading.end();
|
||||||
await TGLogger.Info(`[UserGacha][${account.value.gameUid}][confirmRefresh] 刷新祈愿数据完成`);
|
await TGLogger.Info(`[UserGacha][${account.value.gameUid}][confirmRefresh] 刷新祈愿数据完成`);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGachaLogs(
|
// 刷新单个池子
|
||||||
pool: string,
|
async function refreshGachaPool(
|
||||||
endId: string = "0",
|
type: string,
|
||||||
title: string,
|
label: string,
|
||||||
check?: string,
|
force: boolean = false,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const uid = account.value.gameUid;
|
let endId = "0";
|
||||||
await TGLogger.Info(
|
// 全量刷新时时间与id的对应关系
|
||||||
`[UserGacha][${uid}][getGachaLogs] 获取祈愿数据,pool:${pool},endId:${endId}`,
|
let gachaDataMap: Record<string, string[]> | undefined = undefined;
|
||||||
);
|
if (!force) {
|
||||||
const gachaRes = await Hk4eApi.gacha(authkey.value, pool, endId);
|
showLoading.update(`正在刷新${label}数据`, "正在获取数据库祈愿最新 ID");
|
||||||
console.log(pool, endId, gachaRes);
|
endId = (await TSUserGacha.getGachaCheck(account.value.gameUid, type)) ?? "0";
|
||||||
if (Array.isArray(gachaRes)) {
|
showLoading.update(`正在刷新${label}数据`, `最新 ID:${endId}`);
|
||||||
await TGLogger.Info(
|
} else {
|
||||||
`[UserGacha][${uid}][getGachaLogs] 成功获取到 ${gachaRes.length} 条祈愿数据`,
|
showLoading.update(`正在刷新${label}数据`);
|
||||||
);
|
}
|
||||||
|
while (true) {
|
||||||
|
const gachaRes = await Hk4eApi.gacha(authkey.value, type, endId);
|
||||||
|
if (!Array.isArray(gachaRes)) {
|
||||||
|
showSnackbar.error(`[${type}][${gachaRes.retcode}] ${gachaRes.message}`);
|
||||||
|
await TGLogger.Error(
|
||||||
|
`[UserGacha][${account.value.gameUid}][refreshGachaPool] 获取祈愿数据失败`,
|
||||||
|
);
|
||||||
|
await TGLogger.Error(
|
||||||
|
`[UserGacha][${account.value.gameUid}][refreshGachaPool] ${gachaRes.retcode} ${gachaRes.message}`,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (gachaRes.length === 0) {
|
if (gachaRes.length === 0) {
|
||||||
await new Promise((resolve) => setTimeout(() => resolve(""), 1000));
|
if (force) {
|
||||||
return;
|
showLoading.update(`正在清理${label}数据`);
|
||||||
|
if (gachaDataMap)
|
||||||
|
await TSUserGacha.cleanGachaRecords(account.value.gameUid, type, gachaDataMap);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
const uigfList: TGApp.Plugins.UIGF.GachaItem[] = [];
|
const uigfList: TGApp.Plugins.UIGF.GachaItem[] = [];
|
||||||
gachaRes.forEach((item) => {
|
for (const item of gachaRes) {
|
||||||
showLoading.update(
|
showLoading.update(`正在刷新${label}数据`, `[${item.item_type}][${item.time}] ${item.name}`);
|
||||||
`正在导入 ${title} 数据`,
|
|
||||||
`[${item.item_type}][${item.time}] ${item.name}`,
|
|
||||||
);
|
|
||||||
const tempItem: TGApp.Plugins.UIGF.GachaItem = {
|
const tempItem: TGApp.Plugins.UIGF.GachaItem = {
|
||||||
gacha_type: item.gacha_type,
|
gacha_type: item.gacha_type,
|
||||||
item_id: item.item_id,
|
item_id: item.item_id,
|
||||||
@@ -240,22 +231,15 @@ async function getGachaLogs(
|
|||||||
if (find) tempItem.item_id = find.id.toString();
|
if (find) tempItem.item_id = find.id.toString();
|
||||||
}
|
}
|
||||||
uigfList.push(tempItem);
|
uigfList.push(tempItem);
|
||||||
});
|
if (force) {
|
||||||
await TSUserGacha.mergeUIGF(uid, uigfList);
|
if (!gachaDataMap) gachaDataMap = {};
|
||||||
if (check !== undefined && gachaRes.some((i) => i.id === check)) {
|
if (!gachaDataMap[item.time]) gachaDataMap[item.time] = [];
|
||||||
await new Promise<void>((resolve) => setTimeout(() => resolve(), 1000));
|
gachaDataMap[item.time].push(item.id);
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
if (gachaRes.length === 20) {
|
await TSUserGacha.mergeUIGF(account.value.gameUid, uigfList);
|
||||||
await new Promise<void>((resolve) => setTimeout(() => resolve(), 1000));
|
endId = gachaRes[gachaRes.length - 1].id;
|
||||||
await getGachaLogs(pool, gachaRes[gachaRes.length - 1].id, title, check);
|
await new Promise<void>((resolve) => setTimeout(() => resolve(), 1000));
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showSnackbar.error(`[${pool}][${gachaRes.retcode}] ${gachaRes.message}`);
|
|
||||||
await TGLogger.Error(`[UserGacha][${uid}][getGachaLogs] 获取祈愿数据失败`);
|
|
||||||
await TGLogger.Error(
|
|
||||||
`[UserGacha][${uid}][getGachaLogs] ${gachaRes.retcode} ${gachaRes.message}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import { path } from "@tauri-apps/api";
|
import { path } from "@tauri-apps/api";
|
||||||
import { exists, mkdir, readDir } from "@tauri-apps/plugin-fs";
|
import { exists, mkdir, readDir } from "@tauri-apps/plugin-fs";
|
||||||
|
|
||||||
|
import showSnackbar from "../../../components/func/snackbar.js";
|
||||||
import { AppCharacterData, AppWeaponData } from "../../../data/index.js";
|
import { AppCharacterData, AppWeaponData } from "../../../data/index.js";
|
||||||
import TGLogger from "../../../utils/TGLogger.js";
|
import TGLogger from "../../../utils/TGLogger.js";
|
||||||
import { exportUigfData, readUigfData, verifyUigfData } from "../../../utils/UIGF.js";
|
import { exportUigfData, readUigfData, verifyUigfData } from "../../../utils/UIGF.js";
|
||||||
@@ -151,6 +152,36 @@ async function deleteGachaRecords(uid: string): Promise<void> {
|
|||||||
await db.execute("DELETE FROM GachaRecords WHERE uid = ?;", [uid]);
|
await db.execute("DELETE FROM GachaRecords WHERE uid = ?;", [uid]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 清理祈愿记录
|
||||||
|
* @since Beta v0.6.4
|
||||||
|
* @param {string} uid - UID
|
||||||
|
* @param {string} pool - 池子
|
||||||
|
* @param {Record<string,string[]>} map - 祈愿数据
|
||||||
|
* @return {Promise<void>}
|
||||||
|
*/
|
||||||
|
async function cleanGachaRecords(
|
||||||
|
uid: string,
|
||||||
|
pool: string,
|
||||||
|
map: Record<string, string[]>,
|
||||||
|
): Promise<void> {
|
||||||
|
const db = await TGSqlite.getDB();
|
||||||
|
for (const [time, ids] of Object.entries(map)) {
|
||||||
|
const sql = `DELETE
|
||||||
|
FROM GachaRecords
|
||||||
|
WHERE uid = '${uid}'
|
||||||
|
AND gachaType = '${pool}'
|
||||||
|
AND time = '${time}'
|
||||||
|
AND id NOT IN (${ids.map((i) => `'${i}'`).join(",")});
|
||||||
|
`;
|
||||||
|
const res = await db.execute(sql);
|
||||||
|
if (res.rowsAffected > 0) {
|
||||||
|
showSnackbar.success(`[${uid}][${pool}][${time}]清理了${res.rowsAffected}条祈愿记录`);
|
||||||
|
await new Promise<void>((resolve) => setTimeout(resolve, 1500));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 合并祈愿数据
|
* @description 合并祈愿数据
|
||||||
* @since Beta v0.4.7
|
* @since Beta v0.4.7
|
||||||
@@ -244,6 +275,7 @@ const TSUserGacha = {
|
|||||||
getGachaRecords,
|
getGachaRecords,
|
||||||
getGachaItemType,
|
getGachaItemType,
|
||||||
deleteGachaRecords,
|
deleteGachaRecords,
|
||||||
|
cleanGachaRecords,
|
||||||
mergeUIGF,
|
mergeUIGF,
|
||||||
mergeUIGF4,
|
mergeUIGF4,
|
||||||
backUpUigf,
|
backUpUigf,
|
||||||
|
|||||||
Reference in New Issue
Block a user