fix(UIAF): 方法修正

This commit is contained in:
BTMuli
2023-03-08 21:33:35 +08:00
parent abe5867499
commit 8604790f9d
2 changed files with 36 additions and 33 deletions

View File

@@ -1,11 +1,18 @@
import { checkUIAFData, readUIAFData, importUIAFData } from "./utils/importData"; /**
* @file plugins UIAF index.ts
* @description UIAF plugin index
* @author BTMuli<bt-muli@outlook.com>
* @since Alpha
*/
import { checkUIAFData, readUIAFData, mergeUIAFData } from "./utils/importData";
import { getAchievements } from "./utils/exportData"; import { getAchievements } from "./utils/exportData";
const UIAF_Oper = { const UIAF_Oper = {
importOper: { importOper: {
checkUIAFData, checkUIAFData,
readUIAFData, readUIAFData,
importUIAFData, mergeUIAFData,
}, },
exportOper: { exportOper: {
getAchievements, getAchievements,

View File

@@ -21,9 +21,9 @@ export async function checkUIAFData(path: string): Promise<boolean> {
} }
/** /**
* @description 读取本地 UIAF 数据 * @description 读取 UIAF 数据
* @param {string} userPath - UIAF 数据路径 * @param {string} userPath - UIAF 数据路径
* @return {Promise<string>|Promise<false>} UIAF 数据 * @return {Promise<string|false>} UIAF 数据
*/ */
export async function readUIAFData(userPath: string): Promise<string | false> { export async function readUIAFData(userPath: string): Promise<string | false> {
if (await fs.exists(userPath)) { if (await fs.exists(userPath)) {
@@ -40,15 +40,14 @@ export async function readUIAFData(userPath: string): Promise<string | false> {
/** /**
* @description 数据合并 * @description 数据合并
* @param {UIAF_Achievement[]|false} localData - 本地数据 * @param {UIAF_Achievement[]} localData - 本地数据
* @param {Achievements} remoteData - 远程数据 * @param {Achievements} remoteData - 远程数据
* @return {Promise<UIAF_Achievement[]|false>} 合并后的数据,如果合并失败则返回 false * @return {Promise<UIAF_Achievement[]|false>} 合并后的数据,如果合并失败则返回 false
*/ */
export async function importUIAFData( export async function mergeUIAFData(
localData: UIAF_Achievement[] | false, localData: UIAF_Achievement[],
remoteData: Achievements remoteData: Achievements
): Promise<UIAF_Achievement[] | false> { ): Promise<UIAF_Achievement[] | false> {
if (localData !== false) {
// 遍历 remoteData.list // 遍历 remoteData.list
remoteData.list.map((remoteAchievement: UIAF_Achievement) => { remoteData.list.map((remoteAchievement: UIAF_Achievement) => {
// 查找 id 相同的 localAchievement // 查找 id 相同的 localAchievement
@@ -72,7 +71,4 @@ export async function importUIAFData(
localData.sort((a, b) => a.id - b.id); localData.sort((a, b) => a.id - b.id);
// 返回合并后的数据 // 返回合并后的数据
return localData; return localData;
} else {
return remoteData.list;
}
} }