mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-25 05:29:45 +08:00
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file plugins/Sqlite/modules/userGacha.ts
|
||||
* @description 用户祈愿模块
|
||||
* @since Beta v0.6.8
|
||||
* @since Beta v0.7.5
|
||||
*/
|
||||
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
@@ -10,7 +10,7 @@ import { path } from "@tauri-apps/api";
|
||||
import { exists, mkdir, readDir } from "@tauri-apps/plugin-fs";
|
||||
|
||||
import TGLogger from "@/utils/TGLogger.js";
|
||||
import { getWikiBrief } from "@/utils/toolFunc.js";
|
||||
import { getWikiBrief, timestampToDate } from "@/utils/toolFunc.js";
|
||||
import { exportUigfData, readUigfData, verifyUigfData } from "@/utils/UIGF.js";
|
||||
|
||||
/**
|
||||
@@ -41,20 +41,38 @@ function getInsertSql(uid: string, gacha: TGApp.Plugins.UIGF.GachaItem): string
|
||||
`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 传入时间字符串跟对应时区,转成utc8时间字符串
|
||||
* @since Beta v0.7.5
|
||||
* @param {string} time - 时间字符串
|
||||
* @param {number} timezone - 时区
|
||||
* @return {string} 转换后的时间戳
|
||||
*/
|
||||
function getUtc8Time(time: string, timezone: number): string {
|
||||
const date = new Date(time);
|
||||
const diffTimezone = -timezone + 8;
|
||||
const realDate = new Date(date.getTime() + diffTimezone * 60 * 60 * 1000);
|
||||
return timestampToDate(realDate.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 转换祈愿数据,防止多语言
|
||||
* @since Beta v0.6.8
|
||||
* @since Beta v0.7.5
|
||||
* @param {TGApp.Plugins.UIGF.GachaItem} gacha - UIGF数据
|
||||
* @param {number} timezone - 时区
|
||||
* @return {TGApp.Plugins.UIGF.GachaItem} 转换后的数据
|
||||
*/
|
||||
function transGacha(gacha: TGApp.Plugins.UIGF.GachaItem): TGApp.Plugins.UIGF.GachaItem {
|
||||
function transGacha(
|
||||
gacha: TGApp.Plugins.UIGF.GachaItem,
|
||||
timezone: number = 8,
|
||||
): TGApp.Plugins.UIGF.GachaItem {
|
||||
const find = getWikiBrief(gacha.item_id);
|
||||
if (!find) return gacha;
|
||||
return {
|
||||
gacha_type: gacha.gacha_type,
|
||||
item_id: gacha.item_id,
|
||||
count: gacha.count ?? "1",
|
||||
time: gacha.time,
|
||||
time: getUtc8Time(gacha.time, timezone),
|
||||
name: find.name,
|
||||
item_type: "element" in find ? "角色" : "武器",
|
||||
rank_type: find.star.toString(),
|
||||
@@ -204,7 +222,7 @@ async function mergeUIGF(uid: string, data: TGApp.Plugins.UIGF.GachaItem[]): Pro
|
||||
async function mergeUIGF4(data: TGApp.Plugins.UIGF.GachaHk4e): Promise<void> {
|
||||
const db = await TGSqlite.getDB();
|
||||
for (const gacha of data.list) {
|
||||
const trans = transGacha(gacha);
|
||||
const trans = transGacha(gacha, data.timezone);
|
||||
const sql = getInsertSql(data.uid.toString(), trans);
|
||||
await db.execute(sql);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file utils/UIGF.ts
|
||||
* @description UIGF工具类
|
||||
* @since Beta v0.6.5
|
||||
* @since Beta v0.7.5
|
||||
*/
|
||||
|
||||
import showSnackbar from "@comp/func/snackbar.js";
|
||||
@@ -28,13 +28,28 @@ function getUigfTimeZone(uid: string): number {
|
||||
return 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 传入utc8时间字符串跟目标时区,转成目标时区时间字符串
|
||||
* @since Beta v0.7.5
|
||||
* @param {string} time - 时间字符串
|
||||
* @param {number} timezone - 时区
|
||||
* @return {string} 转换后的时间字符串
|
||||
*/
|
||||
function getExportTime(time: string, timezone: number): string {
|
||||
const date = new Date(time);
|
||||
const diffTimezone = -8 + timezone;
|
||||
const realDate = new Date(date.getTime() + diffTimezone * 60 * 60 * 1000);
|
||||
return timestampToDate(realDate.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取 UIGF 头部信息
|
||||
* @since Beta v0.4.4
|
||||
* @since Beta v0.7.5
|
||||
* @param {string} uid - UID
|
||||
* @param {number} timezone - 时区
|
||||
* @returns {Promise<TGApp.Plugins.UIGF.Info>}
|
||||
*/
|
||||
async function getUigfHeader(uid: string): Promise<TGApp.Plugins.UIGF.Info> {
|
||||
async function getUigfHeader(uid: string, timezone: number): Promise<TGApp.Plugins.UIGF.Info> {
|
||||
const stamp = Date.now();
|
||||
return {
|
||||
uid,
|
||||
@@ -44,7 +59,7 @@ async function getUigfHeader(uid: string): Promise<TGApp.Plugins.UIGF.Info> {
|
||||
export_time: timestampToDate(stamp),
|
||||
export_app: "TeyvatGuide",
|
||||
export_app_version: await app.getVersion(),
|
||||
region_time_zone: getUigfTimeZone(uid),
|
||||
region_time_zone: timezone,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,19 +81,21 @@ export async function getUigf4Header(): Promise<TGApp.Plugins.UIGF.Info4> {
|
||||
|
||||
/**
|
||||
* @description 数据转换-数据库到 UIGF
|
||||
* @since Alpha v0.2.3
|
||||
* @since Beta v0.7.5
|
||||
* @param {TGApp.Sqlite.GachaRecords.SingleTable[]} data - 数据库数据
|
||||
* @param {number} timezone - 时区
|
||||
* @returns {TGApp.Plugins.UIGF.GachaItem[]} UIGF 数据
|
||||
*/
|
||||
function convertDataToUigf(
|
||||
data: TGApp.Sqlite.GachaRecords.SingleTable[],
|
||||
timezone: number,
|
||||
): TGApp.Plugins.UIGF.GachaItem[] {
|
||||
return data.map((gacha) => {
|
||||
return {
|
||||
gacha_type: gacha.gachaType,
|
||||
item_id: gacha.itemId,
|
||||
count: gacha.count,
|
||||
time: gacha.time,
|
||||
time: getExportTime(gacha.time, timezone),
|
||||
name: gacha.name,
|
||||
item_type: gacha.type,
|
||||
rank_type: gacha.rank,
|
||||
@@ -172,7 +189,7 @@ export async function readUigf4Data(userPath: string): Promise<TGApp.Plugins.UIG
|
||||
|
||||
/**
|
||||
* @description 导出 UIGF 数据
|
||||
* @since Beta v0.5.0
|
||||
* @since Beta v0.7.5
|
||||
* @param {string} uid - UID
|
||||
* @param {TGApp.Sqlite.GachaRecords.SingleTable[]} gachaList - 祈愿列表
|
||||
* @param {string} savePath - 保存路径
|
||||
@@ -183,21 +200,23 @@ export async function exportUigfData(
|
||||
gachaList: TGApp.Sqlite.GachaRecords.SingleTable[],
|
||||
savePath?: string,
|
||||
): Promise<void> {
|
||||
const UigfData = { info: await getUigfHeader(uid), list: convertDataToUigf(gachaList) };
|
||||
const timezone = getUigfTimeZone(uid);
|
||||
const UigfData = {
|
||||
info: await getUigfHeader(uid, timezone),
|
||||
list: convertDataToUigf(gachaList, timezone),
|
||||
};
|
||||
const filePath = savePath ?? `${await path.appLocalDataDir()}userData\\UIGF_${uid}.json`;
|
||||
await writeTextFile(filePath, JSON.stringify(UigfData));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取单项UID的UIGF4.0数据
|
||||
* @since Beta v0.7.5
|
||||
* @param {string} uid - UID
|
||||
* @returns {Promise<TGApp.Plugins.UIGF.GachaHk4e>}
|
||||
*/
|
||||
export async function getUigf4Item(uid: string): Promise<TGApp.Plugins.UIGF.GachaHk4e> {
|
||||
const gachaList = await TSUserGacha.getGachaRecords(uid);
|
||||
return {
|
||||
uid: uid,
|
||||
timezone: getUigfTimeZone(uid),
|
||||
list: convertDataToUigf(gachaList),
|
||||
};
|
||||
const timezone = getUigfTimeZone(uid);
|
||||
return { uid: uid, timezone: timezone, list: convertDataToUigf(gachaList, timezone) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user