MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / parseAndSetConfig

Function parseAndSetConfig

eat/eat.ts:66–91  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

64
65async function loadConfigResource(url: string, forceUpdate = false) {
66 const parseAndSetConfig = (content: string) => {
67 const fullConfig = JSON.parse(content);
68 if (!fullConfig.resources) {
69 throw new Error("配置文件格式错误,缺少resources 字段");
70 }
71 const regex =
72 /^https:\/\/raw\.githubusercontent\.com\/([^\/]+)\/([^\/]+)\/refs\/heads\/([^\/]+)\/(.+)$/;
73 const match = url.match(regex);
74 if (!match) throw new Error("URL格式不正确");
75 const [, repo_owner, repo_name, branch] = match;
76 const base_url_template =
77 "https://github.com/${repo_owner}/${repo_name}/raw/${branch}";
78 if (!repo_owner || !repo_name || !branch) {
79 throw new Error("URL格式不正确, 缺少 repo_owner, repo_name, branch等信息");
80 }
81
82 resourceBaseUrl = base_url_template
83 .replace("${repo_owner}", repo_owner)
84 .replace("${repo_name}", repo_name)
85 .replace("${branch}", branch);
86
87 config = fullConfig.resources;
88 console.log(
89 `配置加载成功,当前分支: ${branch}, 资源基础URL: ${resourceBaseUrl}`
90 );
91 };
92
93 if (!forceUpdate && Object.keys(config || {}).length > 0) {
94 return;

Callers 1

loadConfigResourceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected