From 8604790f9d035f1012b8a40947cb2fdaf56ae745 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Wed, 8 Mar 2023 21:33:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(UIAF):=20=E6=96=B9=E6=B3=95=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/UIAF/index.ts | 11 +++++- src/plugins/UIAF/utils/importData.ts | 58 +++++++++++++--------------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/plugins/UIAF/index.ts b/src/plugins/UIAF/index.ts index 9ffd5d46..6f7fa99e 100644 --- a/src/plugins/UIAF/index.ts +++ b/src/plugins/UIAF/index.ts @@ -1,11 +1,18 @@ -import { checkUIAFData, readUIAFData, importUIAFData } from "./utils/importData"; +/** + * @file plugins UIAF index.ts + * @description UIAF plugin index + * @author BTMuli + * @since Alpha + */ + +import { checkUIAFData, readUIAFData, mergeUIAFData } from "./utils/importData"; import { getAchievements } from "./utils/exportData"; const UIAF_Oper = { importOper: { checkUIAFData, readUIAFData, - importUIAFData, + mergeUIAFData, }, exportOper: { getAchievements, diff --git a/src/plugins/UIAF/utils/importData.ts b/src/plugins/UIAF/utils/importData.ts index 8cefae1b..fe42fe8d 100644 --- a/src/plugins/UIAF/utils/importData.ts +++ b/src/plugins/UIAF/utils/importData.ts @@ -21,9 +21,9 @@ export async function checkUIAFData(path: string): Promise { } /** - * @description 读取本地 UIAF 数据 + * @description 读取 UIAF 数据 * @param {string} userPath - UIAF 数据路径 - * @return {Promise|Promise} UIAF 数据 + * @return {Promise} UIAF 数据 */ export async function readUIAFData(userPath: string): Promise { if (await fs.exists(userPath)) { @@ -40,39 +40,35 @@ export async function readUIAFData(userPath: string): Promise { /** * @description 数据合并 - * @param {UIAF_Achievement[]|false} localData - 本地数据 + * @param {UIAF_Achievement[]} localData - 本地数据 * @param {Achievements} remoteData - 远程数据 * @return {Promise} 合并后的数据,如果合并失败则返回 false */ -export async function importUIAFData( - localData: UIAF_Achievement[] | false, +export async function mergeUIAFData( + localData: UIAF_Achievement[], remoteData: Achievements ): Promise { - if (localData !== false) { - // 遍历 remoteData.list - remoteData.list.map((remoteAchievement: UIAF_Achievement) => { - // 查找 id 相同的 localAchievement - const localAchievement = localData.find( - achievement => achievement.id === remoteAchievement.id - ); - // 如果没找到,就直接添加 - if (localAchievement === undefined) { - localData.push(remoteAchievement); - } else { - // 检测数据是否需要更新 - if (localAchievement.timestamp < remoteAchievement.timestamp) { - // 更新数据 - localAchievement.timestamp = remoteAchievement.timestamp; - localAchievement.current = remoteAchievement.current; - localAchievement.status = remoteAchievement.status; - } + // 遍历 remoteData.list + remoteData.list.map((remoteAchievement: UIAF_Achievement) => { + // 查找 id 相同的 localAchievement + const localAchievement = localData.find( + achievement => achievement.id === remoteAchievement.id + ); + // 如果没找到,就直接添加 + if (localAchievement === undefined) { + localData.push(remoteAchievement); + } else { + // 检测数据是否需要更新 + if (localAchievement.timestamp < remoteAchievement.timestamp) { + // 更新数据 + localAchievement.timestamp = remoteAchievement.timestamp; + localAchievement.current = remoteAchievement.current; + localAchievement.status = remoteAchievement.status; } - }); - // 按照 id 排序 - localData.sort((a, b) => a.id - b.id); - // 返回合并后的数据 - return localData; - } else { - return remoteData.list; - } + } + }); + // 按照 id 排序 + localData.sort((a, b) => a.id - b.id); + // 返回合并后的数据 + return localData; }