diff --git a/sub2proxy.js b/sub2proxy.js index 710184e..48e6841 100644 --- a/sub2proxy.js +++ b/sub2proxy.js @@ -336,21 +336,45 @@ function renameNode(node, subName, isClash = true) { } function detectTemplates() { - let yamlTpl = 'CatMata.optimized.yaml'; + const tplDir = 'templates'; + let yamlTpl = path.join(tplDir, 'CatMata.optimized.yaml'); + let jsonTpl = path.join(tplDir, 'CatMata.json'); + if (!fs.existsSync(yamlTpl)) { - const yamls = fs.readdirSync('.').filter(f => f.endsWith('.yaml') || f.endsWith('.yml')); - const matched = yamls.find(f => f.includes('CatMata')); - if (matched) yamlTpl = matched; + if (fs.existsSync(tplDir)) { + const yamls = fs.readdirSync(tplDir).filter(f => f.endsWith('.yaml') || f.endsWith('.yml')); + const matched = yamls.find(f => f.includes('CatMata')); + if (matched) yamlTpl = path.join(tplDir, matched); + } else { + yamlTpl = 'CatMata.optimized.yaml'; + if (!fs.existsSync(yamlTpl)) { + const yamls = fs.readdirSync('.').filter(f => f.endsWith('.yaml') || f.endsWith('.yml')); + const matched = yamls.find(f => f.includes('CatMata')); + if (matched) yamlTpl = matched; + } + } } - let jsonTpl = 'CatMata.json'; if (!fs.existsSync(jsonTpl)) { - if (fs.existsSync('CatMata-tun.json')) { - jsonTpl = 'CatMata-tun.json'; + if (fs.existsSync(tplDir)) { + if (fs.existsSync(path.join(tplDir, 'CatMata-tun.json'))) { + jsonTpl = path.join(tplDir, 'CatMata-tun.json'); + } else { + const jsons = fs.readdirSync(tplDir).filter(f => f.endsWith('.json')); + const matched = jsons.find(f => f.includes('CatMata')); + if (matched) jsonTpl = path.join(tplDir, matched); + } } else { - const jsons = fs.readdirSync('.').filter(f => f.endsWith('.json') && f !== 'subs.json'); - const matched = jsons.find(f => f.includes('CatMata')); - if (matched) jsonTpl = matched; + jsonTpl = 'CatMata.json'; + if (!fs.existsSync(jsonTpl)) { + if (fs.existsSync('CatMata-tun.json')) { + jsonTpl = 'CatMata-tun.json'; + } else { + const jsons = fs.readdirSync('.').filter(f => f.endsWith('.json') && f !== 'subs.json'); + const matched = jsons.find(f => f.includes('CatMata')); + if (matched) jsonTpl = matched; + } + } } } return { yamlTpl, jsonTpl }; diff --git a/CatMata-tproxy.json b/templates/CatMata-tproxy.json similarity index 100% rename from CatMata-tproxy.json rename to templates/CatMata-tproxy.json diff --git a/CatMata-tun.json b/templates/CatMata-tun.json similarity index 100% rename from CatMata-tun.json rename to templates/CatMata-tun.json diff --git a/CatMata.json b/templates/CatMata.json similarity index 100% rename from CatMata.json rename to templates/CatMata.json diff --git a/CatMata.optimized.yaml b/templates/CatMata.optimized.yaml similarity index 100% rename from CatMata.optimized.yaml rename to templates/CatMata.optimized.yaml diff --git a/CatMata.shellcrash.yaml b/templates/CatMata.shellcrash.yaml similarity index 100% rename from CatMata.shellcrash.yaml rename to templates/CatMata.shellcrash.yaml diff --git a/CatMata.transparent.yaml b/templates/CatMata.transparent.yaml similarity index 100% rename from CatMata.transparent.yaml rename to templates/CatMata.transparent.yaml diff --git a/CatMata.yaml b/templates/CatMata.yaml similarity index 100% rename from CatMata.yaml rename to templates/CatMata.yaml diff --git a/CatMata_b.json b/templates/CatMata_b.json similarity index 100% rename from CatMata_b.json rename to templates/CatMata_b.json