Skip to content

Commit fe4dd5c

Browse files
author
Taois
committed
fix: 修复猫爪使用bug
1 parent 39beef6 commit fe4dd5c

File tree

4 files changed

+264
-344
lines changed

4 files changed

+264
-344
lines changed

controllers/config.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ import batchExecute from '../libs_drpy/batchExecute.js';
1515

1616
const {jsEncoder} = drpyS;
1717

18+
function parseExt(str) {
19+
try {
20+
const parsed = JSON.parse(str);
21+
if (Array.isArray(parsed) || (typeof parsed === 'object' && parsed !== null)) {
22+
return parsed;
23+
}
24+
} catch (e) {
25+
// 忽略错误
26+
}
27+
return str;
28+
}
29+
30+
function logExt(_ext) {
31+
return Array.isArray(_ext) || typeof _ext == "object" ? JSON.stringify(_ext) : _ext
32+
}
33+
1834
// 工具函数:生成 JSON 数据
1935
async function generateSiteJSON(options, requestHost, sub, pwd) {
2036
const jsDir = options.jsDir;
@@ -373,11 +389,8 @@ async function generateSiteJSON(options, requestHost, sub, pwd) {
373389
let key = `hipy_py_${it.alias}`;
374390
let name = `${it.alias}(hipy)`;
375391
let _ext = it.queryStr;
376-
try {
377-
_ext = JSON.parse(_ext);
378-
} catch (err) {
379-
}
380-
console.log(`[HIPY-${baseName}] alias name: ${name},typeof _ext:${typeof _ext},_ext: ${_ext}`);
392+
_ext = parseExt(_ext);
393+
console.log(`[HIPY-${baseName}] alias name: ${name},typeof _ext:${typeof _ext},_ext: ${logExt(_ext)}`);
381394
fileSites.push({key, name, ext: _ext});
382395
});
383396
} else {
@@ -468,12 +481,8 @@ async function generateSiteJSON(options, requestHost, sub, pwd) {
468481
let key = `catvod_${it.alias}`;
469482
let name = `${it.alias}(cat)`;
470483
let _ext = it.queryStr;
471-
472-
try {
473-
_ext = JSON.parse(_ext);
474-
} catch (err) {
475-
}
476-
console.log(`[CAT-${baseName}] alias name: ${name},typeof _ext:${typeof _ext},_ext: ${_ext}`);
484+
_ext = parseExt(_ext);
485+
console.log(`[CAT-${baseName}] alias name: ${name},typeof _ext:${typeof _ext},_ext: ${logExt(_ext)}`);
477486
fileSites.push({key, name, ext: _ext});
478487
});
479488
} else {
@@ -753,10 +762,13 @@ export default (fastify, options, done) => {
753762
// }
754763
// }
755764
const getFilePath = (cfgPath, rootDir, fileName) => path.join(rootDir, `data/cat/${fileName}`);
756-
const processContent = (content, cfgPath, requestUrl) =>
757-
content.replace('$config_url', requestUrl.replace(cfgPath, `/1?sub=all&pwd=${process.env.API_PWD || ''}`));
765+
const processContent = (content, cfgPath, requestUrl, requestHost) => {
766+
const $config_url = requestUrl.replace(cfgPath, `/1?sub=all&pwd=${process.env.API_PWD || ''}`);
767+
return content.replaceAll('$config_url', $config_url).replaceAll('$host', requestHost);
768+
}
769+
758770

759-
const handleJavaScript = (cfgPath, requestUrl, options, reply) => {
771+
const handleJavaScript = (cfgPath, requestUrl, requestHost, options, reply) => {
760772
const fileMap = {
761773
'index.js': 'index.js',
762774
'index.config.js': 'index.config.js'
@@ -766,7 +778,7 @@ export default (fastify, options, done) => {
766778
if (cfgPath.includes(key)) {
767779
const filePath = getFilePath(cfgPath, options.rootDir, fileName);
768780
let content = readFileSync(filePath, 'utf-8');
769-
content = processContent(content, cfgPath, requestUrl);
781+
content = processContent(content, cfgPath, requestUrl, requestHost);
770782
return reply.type('application/javascript;charset=utf-8').send(content);
771783
}
772784
}
@@ -790,7 +802,7 @@ export default (fastify, options, done) => {
790802
}
791803
};
792804
if (cfg_path.endsWith('.js')) {
793-
return handleJavaScript(cfg_path, requestUrl, options, reply);
805+
return handleJavaScript(cfg_path, requestUrl, requestHost, options, reply);
794806
}
795807

796808
if (cfg_path.endsWith('.js.md5')) {

data/cat/index.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var index_config_default = {
2727
config_url: "$config_url",
2828
// 本地ds 支持
2929
// config_url: 'http://localhost:5707/config/0?sub=dzyyds', // 本地hipy-t4 支持
30-
home_site: "http://localhost:5757/api/设置中心",
30+
home_site: "$host/api/设置中心",
3131
enable_dspush: 1,
3232
enable_home_site: 0,
3333
sniffer_rule: "http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|http((?!http).)*?video/tos*|http((?!http).)*?obj/tos*",

data/cat/index.js

Lines changed: 234 additions & 327 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/updateRecord.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
2. 增加 `live2cms.json` 增加一条本代线路
99
3. 猫源解析引擎默认 0 和 1 都视为url模式,以前base64模式有Bug调整 `CAT_DEBUG=2` 开启
1010
4. 完善hipy源和cat源的map传参机制,map里传参分发源,不用手写配置文件的ext
11+
5. 修复 `猫爪` 软件不支持 源的ext为object对象的问题
1112

1213
已知bug(待壳子适配):
1314

0 commit comments

Comments
 (0)