From 71097a9966ec8a5e29c229909d9be21e19520c33 Mon Sep 17 00:00:00 2001 From: yan Date: Mon, 9 Feb 2026 22:04:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor(bgi=5Ftools):=20=E9=87=8D=E6=9E=84BGI?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=85=8D=E7=BD=AE=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改pullJsonConfig函数参数结构,移除默认值并优化HTTP请求处理逻辑 - 更新pushAllJsonConfig函数参数结构,修改数据传输格式为json对象包装 - 简化配置文件路径定义,移除冗余的相对路径前缀 - 移除配置文件中的大量硬编码领域数据,改为动态读取配置文件 - 在main.js中更新函数调用参数,传递正确的API端点地址 - 修复settings.json中的选项字段名从option改为options - 移除配置文件中的重复分隔注释行 - 添加getConfig导出函数用于外部获取配置对象 - 增加调试日志输出以支持配置加载过程追踪 --- repo/js/AutoPlanDomain/config/config.js | 266 ++-------------------- repo/js/AutoPlanDomain/config/domain.json | 2 - repo/js/AutoPlanDomain/main.js | 17 +- repo/js/AutoPlanDomain/settings.json | 2 +- repo/js/AutoPlanDomain/utils/bgi_tools.js | 53 +++-- 5 files changed, 55 insertions(+), 285 deletions(-) diff --git a/repo/js/AutoPlanDomain/config/config.js b/repo/js/AutoPlanDomain/config/config.js index e151a9b6e..f43705077 100644 --- a/repo/js/AutoPlanDomain/config/config.js +++ b/repo/js/AutoPlanDomain/config/config.js @@ -25,8 +25,8 @@ const config = { // path: { manifest: "manifest.json", - domain: `./config/domain.json`, - domainConfig: `./config/domain_config.json` + domain: "config/domain.json", + domainConfig: "config/domain_config.json" }, //所有秘境信息 domainList: [], @@ -156,253 +156,6 @@ async function checkKey(key = "") { * @returns {Promise} */ async function initConfig() { - /* const domainList = [ - { - name: "无光的深都", - type: "天赋", - hasOrder: true,//存在排序(限时/周日) - list: ["「月光」的哲学", "「乐园」的哲学", "「浪迹」的哲学"] - }, - { - name: "蕴火的幽墟", - type: "天赋", - hasOrder: true,//存在排序(限时/周日) - list: ["「角逐」的哲学", "「焚燔」的哲学", "「纷争」的哲学"] - } - , - { - name: "苍白的遗荣", - type: "天赋", - hasOrder: true,//存在排序(限时/周日) - list: ["「公平」的哲学", "「正义」的哲学", "「秩序」的哲学"] - } - , - { - name: "昏识塔", - type: "天赋", - hasOrder: true,//存在排序(限时/周日) - list: ["「诤言」的哲学", "「巧思」的哲学", "「笃行」的哲学"] - } - , - { - name: "董色之庭", - type: "天赋", - hasOrder: true,//存在排序(限时/周日) - list: ["「浮世」的哲学", "「风雅」的哲学", "「天光」的哲学"] - } - , - { - name: "太山府", - type: "天赋", - hasOrder: true,//存在排序(限时/周日) - list: ["「繁荣」的哲学", "「勤劳」的哲学", "「黄金」的哲学"] - } - , - { - name: "忘却之峡", - type: "天赋", - hasOrder: true,//存在排序(限时/周日) - list: ["「自由」的哲学", "「抗争」的哲学", "「纷争」的哲学"] - } - //================================ - , - { - name: "失落的月庭", - type: "武器", - hasOrder: true,//存在排序(限时/周日) - list: ["奇巧秘器的真愿", "长夜火的烈辉", "终北遗嗣的煌熠"] - } - , - { - name: "深古瞭望所", - type: "武器", - hasOrder: true,//存在排序(限时/周日) - list: ["神合秘烟的启示", "谚妄圣主的神面", "贡祭炽心的荣膺"] - } - , - { - name: "深潮的余响", - type: "武器", - hasOrder: true,//存在排序(限时/周日) - list: ["悠古弦音的回响", "纯圣露滴的真粹", "无垢之海的金杯"] - } - , - { - name: "有顶塔", - type: "武器", - hasOrder: true,//存在排序(限时/周日) - list: ["谧林涓露的金符", "绿洲花园的真谛", "烈日威权的旧日"] - } - , - { - name: "砂流之庭", - type: "武器", - hasOrder: true,//存在排序(限时/周日) - list: ["远海夷地的金枝", "鸣神御灵的勇武", "今昔剧画之鬼人"] - } - , - { - name: "震雷连山密宫", - type: "武器", - hasOrder: true,//存在排序(限时/周日) - list: ["孤云寒林的神体", "雾海云间的转还", "漆黑陨铁的一块"] - } - , - { - name: "塞西莉亚苗圃", - type: "武器", - hasOrder: true,//存在排序(限时/周日) - list: ["高塔孤王的碎梦", "凛风奔狼的怀乡", "狮牙斗士的理想"] - } - //================================ - , - { - name: "月童的库藏", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["风起之日", "晨星与月的晓歌"] - } - , - { - name: "霜凝的机枢", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["纺月的夜歌", "穹境示现之夜"] - } - , - { - name: "荒废砌造坞", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["深廊终曲", "长夜之誓"] - } - , - { - name: "虹灵的净土", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["黑曜秘典", "城勇者绘卷"] - } - , - { - name: "褪色的剧场", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["未竟的遐思", "谐律异想断章"] - } - , - { - name: "临瀑之城", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["回声之林夜话", "昔时之歌"] - } - , - { - name: "罪祸的终末", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["黄金剧团", "逐影猎人"] - } - , - { - name: "熔铁的孤塞", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["花海甘露之光", "水仙之梦"] - } - , - { - name: "赤金的城墟", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["乐园遗落之花", "沙上楼阁史话"] - } - , - { - name: "赤金的城墟", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["乐园遗落之花", "沙上楼阁史话"] - } - , - { - name: "缘觉塔", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["饰金之梦", "深林的记忆"] - } - , - { - name: "沉眠之庭", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["海染砗磲", "华馆梦醒形骸记"] - } - , - { - name: "花染之庭", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["绝缘之旗印", "追忆之注连"] - } - , - { - name: "岩中幽谷", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["辰砂往生录", "来歆余响"] - } - , - { - name: "华池岩柚", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["染血的骑士道", "昔日宗室之仪"] - } - , - { - name: "无妄引答密宫", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["炽烈的炎之魔女", "渡过烈火的贤人"] - } - , - { - name: "孤云凌霄之处", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["悠古的磐岩", "逆飞的流星"] - } - , - { - name: "山脊守望", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["千岩牢固", "苍白之火"] - } - , - { - name: "芬德尼尔之顶", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["冰风迷途的勇士", "沉沦之心"] - } - , - { - name: "铭记之谷", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["翠绿之影", "被怜爱的少女"] - } - , - { - name: "仲夏庭园", - type: "圣遗物", - hasOrder: false,//存在排序(限时/周日) - list: ["如雷的盛怒", "平息鸣雷的尊者"] - } - ]*/ config.info.key = settings.key || config.info.key if (config.info?.key) { if (config.info.key !== config.info.manifest?.key) { @@ -410,10 +163,15 @@ async function initConfig() { } } config.user.uid = await ocrUid() - config.bgi_tools.api.httpPullJsonConfig=settings.bgi_tools_http_pull_json_config - config.bgi_tools.api.httpPushAllJsonConfig=settings.bgi_tools_http_push_all_json_config - config.bgi_tools.open.open_push=settings.bgi_tools_open_push - + config.bgi_tools.api.httpPullJsonConfig = settings.bgi_tools_http_pull_json_config + config.bgi_tools.api.httpPushAllJsonConfig = settings.bgi_tools_http_push_all_json_config + config.bgi_tools.open.open_push = settings.bgi_tools_open_push + log.info(`|bgi_tools:{1}`, JSON.stringify(config.bgi_tools)) + // const text = file.readTextSync(config.path.domain); + // log.info("config.path.domain:{1}",config.path.domain) + // log.info("text:{2}",text) + // const list = JSON.parse(text); + // log.info("list:{3}",[...list]) const domainList = JSON.parse(file.readTextSync(config.path.domain)) || [{ name: undefined, type: undefined, @@ -467,6 +225,8 @@ async function initConfig() { config.domain.loads = loads } + + export { config, LoadType, LoadMap, checkKey, diff --git a/repo/js/AutoPlanDomain/config/domain.json b/repo/js/AutoPlanDomain/config/domain.json index 6b53669fa..f481a0cbb 100644 --- a/repo/js/AutoPlanDomain/config/domain.json +++ b/repo/js/AutoPlanDomain/config/domain.json @@ -69,7 +69,6 @@ "「纷争」的哲学" ] } - //================================ , { "name": "失落的月庭", @@ -141,7 +140,6 @@ "狮牙斗士的理想" ] } - //================================ , { "name": "月童的库藏", diff --git a/repo/js/AutoPlanDomain/main.js b/repo/js/AutoPlanDomain/main.js index c0b6eb3bf..1bb2920e4 100644 --- a/repo/js/AutoPlanDomain/main.js +++ b/repo/js/AutoPlanDomain/main.js @@ -136,7 +136,7 @@ async function loadMode(Load, autoFightOrderSet, domainConfig) { case LoadType.bgi_tools: // 通过bgi_tools方式加载配置 log.info(`开始拉取bgi_tools配置`) - const uidConfigListBgiTools = await pullJsonConfig(config.user.uid + '') || [] + const uidConfigListBgiTools = await pullJsonConfig(config.user.uid + '',config.bgi_tools.api.httpPullJsonConfig) || [] if (uidConfigListBgiTools?.length > 0) { // 如果配置列表不为空,遍历并添加到结果集合中 uidConfigListBgiTools.forEach(item => { @@ -214,7 +214,7 @@ async function main() { await init(); if (config.bgi_tools.open.open_push) { log.info(`开始推送bgi_tools配置`) - await pushAllJsonConfig(JSON.stringify(file.readTextSync(config.path.domain))) + await pushAllJsonConfig(JSON.parse(file.readTextSync(config.path.domain)),config.bgi_tools.api.httpPushAllJsonConfig) } // 获取秘境配置 let domainConfig = config.domain.config; @@ -225,3 +225,16 @@ async function main() { } await main() +async function test() { + await init(); + const text = file.readTextSync(config.path.domain); + // log.info("settings:{1}",config.info.settings) + // log.info("text:{1}",text) + const list = JSON.parse(text); + // log.info("list:{1}",list) + log.info("httpPullJsonConfig:{1}",JSON.parse(JSON.stringify(config.bgi_tools)).api.httpPushAllJsonConfig) + log.info("|test==>config.bgi_tools:{1}",JSON.stringify(config.bgi_tools)) + await pushAllJsonConfig(list,config.bgi_tools.api.httpPushAllJsonConfig) +} + +// await test() \ No newline at end of file diff --git a/repo/js/AutoPlanDomain/settings.json b/repo/js/AutoPlanDomain/settings.json index 97b450409..918556bb7 100644 --- a/repo/js/AutoPlanDomain/settings.json +++ b/repo/js/AutoPlanDomain/settings.json @@ -8,7 +8,7 @@ "name": "auto_load", "type": "multi-checkbox", "label": "加载模式\n全选时相同的配置输入加载会覆盖UID加载\n自动秘境计划配置(属于输入加载)\nconfig/domain_config.json(属于UID加载)\nhttp获取配置(属于bgi_tools加载)", - "option": ["输入加载","UID加载","bgi_tools加载"] , + "options": ["输入加载","UID加载","bgi_tools加载"] , "default": ["输入加载","UID加载"] }, { diff --git a/repo/js/AutoPlanDomain/utils/bgi_tools.js b/repo/js/AutoPlanDomain/utils/bgi_tools.js index 093619fc1..bbe0f77eb 100644 --- a/repo/js/AutoPlanDomain/utils/bgi_tools.js +++ b/repo/js/AutoPlanDomain/utils/bgi_tools.js @@ -6,45 +6,44 @@ import {config} from "../config/config"; * @param http_api * @returns {Promise} */ -async function pullJsonConfig(uid, http_api = config.bgi_tools.api.httpPullJsonConfig) { - const result = http.request("GET", http_api, JSON.stringify({ +async function pullJsonConfig(uid, http_api) { + const res = await http.request("GET", http_api, JSON.stringify({ uid: uid, }) // , JSON.stringify({"Content-Type": "application/json"}) - ).then(res => { - log.debug(`[{0}]res=>{1}`, 'next', JSON.stringify(res)) - if (res.status_code === 200 && res.body) { - let result_json = JSON.parse(res.body); - if (result_json?.code === 200) { - return result_json?.data - } - throw new Error("请求失败,error:" + result_json?.message) + ) + log.debug(`[{0}]res=>{1}`, 'next', JSON.stringify(res)) + if (res.status_code === 200 && res.body) { + let result_json = JSON.parse(res.body); + if (result_json?.code === 200) { + return result_json?.data } - return undefined - }) - return result + throw new Error("请求失败,error:" + result_json?.message) + } + return undefined } /** * 推送全部Json数据 * @param Json * @param http_api - * @returns {Promise} + * @returns {Promise} */ -async function pushAllJsonConfig(Json = "[]", http_api = config.bgi_tools.api.httpPushAllJsonConfig) { - const result = http.request("POST", http_api, Json - , JSON.stringify({"Content-Type": "application/json"}) - ).then(res => { - log.debug(`[{0}]res=>{1}`, 'next', JSON.stringify(res)) - if (res.status_code === 200 && res.body) { - let result_json = JSON.parse(res.body); - if (result_json?.code === 200) { - return result_json?.data - } - throw new Error("请求失败,error:" + result_json?.message) +async function pushAllJsonConfig(list = [], http_api) { + log.info(`list:{1},http:{2}`, list, http_api) + const res = await http.request("POST", http_api, JSON.stringify({json: JSON.stringify(list)}), JSON.stringify({ + "Content-Type": "application/json" + })) + + log.debug(`[{0}]res=>{1}`, 'next', JSON.stringify(res)) + if (res.status_code === 200 && res.body) { + let result_json = JSON.parse(res.body); + if (result_json?.code === 200) { + return result_json?.data } - return undefined - }) + throw new Error("请求失败,error:" + result_json?.message) + } + return undefined } export {