Files
bettergi-scripts-list/repo/js/AutoPlanDomain/utils/bgi_tools.js
yan 71097a9966 refactor(bgi_tools): 重构BGI工具配置管理功能
- 修改pullJsonConfig函数参数结构,移除默认值并优化HTTP请求处理逻辑
- 更新pushAllJsonConfig函数参数结构,修改数据传输格式为json对象包装
- 简化配置文件路径定义,移除冗余的相对路径前缀
- 移除配置文件中的大量硬编码领域数据,改为动态读取配置文件
- 在main.js中更新函数调用参数,传递正确的API端点地址
- 修复settings.json中的选项字段名从option改为options
- 移除配置文件中的重复分隔注释行
- 添加getConfig导出函数用于外部获取配置对象
- 增加调试日志输出以支持配置加载过程追踪
2026-02-09 22:04:47 +08:00

52 lines
1.5 KiB
JavaScript

import {config} from "../config/config";
/**
* 拉取对应uid的Json数据
* @param uid
* @param http_api
* @returns {Promise<HttpResponse>}
*/
async function pullJsonConfig(uid, http_api) {
const res = await http.request("GET", http_api, JSON.stringify({
uid: uid,
})
// , 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
}
throw new Error("请求失败,error:" + result_json?.message)
}
return undefined
}
/**
* 推送全部Json数据
* @param Json
* @param http_api
* @returns {Promise<HttpResponse>}
*/
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
}
throw new Error("请求失败,error:" + result_json?.message)
}
return undefined
}
export {
pullJsonConfig,
pushAllJsonConfig
}