mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-12 09:18:14 +08:00
🎨 refactor(UIAF): 目录结构优化
This commit is contained in:
58
src/utils/UIAF.ts
Normal file
58
src/utils/UIAF.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @description 获取 UIAF 头部信息
|
||||
* @since Alpha v0.1.2
|
||||
* @returns {Promise<TGPlugin.UIAF.Header>}
|
||||
*/
|
||||
|
||||
import { app, fs } from "@tauri-apps/api";
|
||||
|
||||
/**
|
||||
* @description 获取 UIAF 头部信息
|
||||
* @since Alpha v0.1.2
|
||||
* @returns {Promise<TGPlugin.UIAF.Header>}
|
||||
*/
|
||||
|
||||
export async function getHeader (): Promise<TGPlugin.UIAF.Header> {
|
||||
return {
|
||||
// eslint-disable-next-line camelcase
|
||||
export_app: "Tauri.Genshin",
|
||||
// eslint-disable-next-line camelcase
|
||||
export_timestamp: Math.floor(Date.now() / 1000),
|
||||
// eslint-disable-next-line camelcase
|
||||
export_app_version: await app.getVersion(),
|
||||
// eslint-disable-next-line camelcase
|
||||
uiaf_version: "v1.1",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 检测是否存在 UIAF 数据
|
||||
* @description 粗略检测,不保证数据完整性
|
||||
* @since Alpha v0.1.2
|
||||
* @param {string} path - UIAF 数据路径
|
||||
* @returns {Promise<boolean>} 是否存在 UIAF 数据
|
||||
*/
|
||||
export async function verifyUIAF (path: string): Promise<boolean> {
|
||||
const fileData: string = await fs.readTextFile(path);
|
||||
const UIAFData: TGPlugin.UIAF.Header = 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 readUIAF (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