mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-04-05 07:15:06 +08:00
🎨 refactor(UIAF): 目录结构优化
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* @file plugins UIAF index.ts
|
||||
* @description UIAF plugin index
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
|
||||
import { checkUiafData, readUiafData } from "./utils/importData";
|
||||
import { getUiafInfo } from "./utils/exportData";
|
||||
|
||||
const UiafOper = {
|
||||
checkUiafData,
|
||||
readUiafData,
|
||||
getUiafInfo,
|
||||
};
|
||||
|
||||
export default UiafOper;
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* @file plugins UIAF interface UIAF.ts
|
||||
* @description UIAF interface
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @see https://github.com/DGP-Studio/Snap.Genshin.Docs/blob/main/docs/development/UIAF.md
|
||||
* @version v1.1
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
|
||||
/**
|
||||
* @interface Achievements
|
||||
* @description UIAF 成就数据
|
||||
* @property {UIAF_Info} info UIAF 头部信息
|
||||
* @property {UIAF_Achievement[]} list UIAF 成就列表
|
||||
* @returns {Achievements}
|
||||
*/
|
||||
export interface Achievements {
|
||||
info: UiafHeader
|
||||
list: UiafAchievement[]
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface UiafHeader
|
||||
* @description UIAF 头部信息
|
||||
* @property {string} export_app 导出的应用名称
|
||||
* @property {number} export_timestamp 导出时间戳,正确时间戳得乘以 1000
|
||||
* @property {string} export_app_version 导出的应用版本
|
||||
* @property {string} uiaf_version UIAF 版本
|
||||
* @returns {UiafHeader}
|
||||
*/
|
||||
export interface UiafHeader {
|
||||
export_app: string
|
||||
export_timestamp: number
|
||||
export_app_version: string
|
||||
uiaf_version: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface UiafAchievement
|
||||
* @since Alpha v0.1.2
|
||||
* @description UIAF 单个成就数据
|
||||
* @property {number} id 成就 ID
|
||||
* @property {number} timestamp 成就记录时间戳,正确时间戳得乘以 1000
|
||||
* @property {number} current 成就进度
|
||||
* @property {number} status 成就状态,0 为未完成,1 为已完成
|
||||
* @returns {UiafAchievement}
|
||||
*/
|
||||
export interface UiafAchievement {
|
||||
id: number
|
||||
timestamp: number
|
||||
current: number
|
||||
status: number
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/**
|
||||
* @file plugins UIAF utils exportData.ts
|
||||
* @description UIAF export data utils
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
|
||||
import { type UiafHeader } from "../interface/UIAF";
|
||||
import { app } from "@tauri-apps/api";
|
||||
|
||||
/**
|
||||
* @description 获取 UIAF 头部信息
|
||||
* @since Alpha v0.1.2
|
||||
* @returns {Promise<UiafHeader>}
|
||||
*/
|
||||
export async function getUiafInfo (): Promise<UiafHeader> {
|
||||
return {
|
||||
export_app: "Tauri.Genshin",
|
||||
export_timestamp: Math.floor(Date.now() / 1000),
|
||||
export_app_version: await app.getVersion(),
|
||||
uiaf_version: "v1.1",
|
||||
};
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* @file plugins UIAF utils importData.ts
|
||||
* @description UIAF import data utils
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
|
||||
import { type UiafHeader } from "../interface/UIAF";
|
||||
import { fs } from "@tauri-apps/api";
|
||||
|
||||
/**
|
||||
* @description 检测是否存在 UIAF 数据
|
||||
* @description 粗略检测,不保证数据完整性
|
||||
* @since Alpha v0.1.2
|
||||
* @param {string} path - UIAF 数据路径
|
||||
* @returns {Promise<boolean>} 是否存在 UIAF 数据
|
||||
*/
|
||||
export async function checkUiafData (path: string): Promise<boolean> {
|
||||
const fileData: string = await fs.readTextFile(path);
|
||||
const UIAFData: UiafHeader = JSON.parse(fileData).info;
|
||||
return UIAFData.uiaf_version !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 读取 UIAF 数据
|
||||
* @since Alpha v0.1.2
|
||||
* @param {string} userPath - UIAF 数据路径
|
||||
* @returns {Promise<string|false>} UIAF 数据
|
||||
*/
|
||||
export async function readUiafData (userPath: string): Promise<string | false> {
|
||||
if (await fs.exists(userPath)) {
|
||||
const fileData = await fs.readTextFile(userPath);
|
||||
if (fileData !== undefined && fileData !== null && fileData !== "" && fileData !== "{}") {
|
||||
return fileData;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user