From 4a064944d74c585f5523a92bcd3a0a0863ee01ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E7=AB=AF=E5=AE=A2?= <107686912+Kirito520Asuna@users.noreply.github.com> Date: Mon, 24 Aug 2026 15:43:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor(AutoPlan):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=E5=AF=BC=E5=85=A5=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=B9=B6=E5=AE=9E=E7=8E=B0=E8=AE=B0=E5=BD=95=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20(#3561)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 Record 工具类的导入路径从 "../ActivitySwitchNotice/utils/tool" 修改为 "./utils/tool" - 新增 Record 类实现记录文件的读取、写入和存在性检查功能 - 添加 Record.read 方法用于解析指定路径的记录文件 - 添加 Record.existInList 方法用于检查记录项是否存在于列表中 - 添加 Record.exist 方法用于检查记录文件中是否存在指定记录 - 添加 Record.write 方法用于将记录列表写入指定路径的文件 - 完善相关方法的 JSDoc 注释文档 --- repo/js/AutoPlan/main.js | 2 +- repo/js/AutoPlan/utils/tool.js | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/repo/js/AutoPlan/main.js b/repo/js/AutoPlan/main.js index 9618f4702..451503f1b 100644 --- a/repo/js/AutoPlan/main.js +++ b/repo/js/AutoPlan/main.js @@ -12,7 +12,7 @@ import { initRunOrderList, checkAndFilterStygianOnslaught } from './utils/load_check_run' -import {Record} from "../ActivitySwitchNotice/utils/tool"; +import {Record} from "./utils/tool"; import {checkHolyRelicsKey} from "./utils/HolyRelics"; /** diff --git a/repo/js/AutoPlan/utils/tool.js b/repo/js/AutoPlan/utils/tool.js index 600f8694f..074bca070 100644 --- a/repo/js/AutoPlan/utils/tool.js +++ b/repo/js/AutoPlan/utils/tool.js @@ -647,4 +647,58 @@ export function StringFormat(format, ...args) { return match; } }); +} + +export class Record { + /** + * 读取指定路径的记录文件 + * @param {string} path - 记录文件的路径 + * @returns {Array} 解析后的记录数组,若文件为空或解析失败则返回空数组 + */ + static read(path) { + // a = { + // uid: 1, + // time: "yyyy-mm-dd", + // key: "type:value" + // } + let list = [] + try { + list = JSON.parse(file.readTextSync(path)) + } catch (e) { + log.warn(`(账号未运行过无记录文件 请忽略该异常),读取记录文件失败,{0}`, e.message) + } + return list + } + + /** + * 在列表中检查指定记录是否存在 + * @param {Array} list - 记录列表,默认为空数组 + * @param {Object} item - 用于匹配的记录项,包含 key, time, uid 属性 + * @returns {boolean} + */ + static existInList(list = [], item) { + const ts = item?.id ? list.filter(i => i.id === item.id && i.time === item.time && i.uid === item.uid) : list.filter(i => i.key === item.key && i.time === item.time && i.uid === item.uid); + return ts !== null && ts.length > 0 + } + + /** + * 检查指定记录是否存在 + * @param {string} path - 记录文件的路径 + * @param {Object} item - 用于匹配的记录项,包含 key, time, uid 属性 + * @returns {boolean} + */ + static exist(path, item) { + const ts = Record.read(path).filter(i => i.key === item.key && i.time === item.time && i.uid === item.uid); + return ts !== null && ts.length > 0 + } + + /** + * 将记录列表写入指定路径的文件 + * @param {string} path - 目标文件的路径 + * @param {Array} list - 要写入的记录列表 + * @returns {*} 返回 parse 变量(注:当前代码中 parse 未在此函数内定义) + */ + static write(path, list) { + file.writeTextSync(path, JSON.stringify(list)) + } } \ No newline at end of file