Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6faea123c6 |
No files matched your search
@@ -1,106 +0,0 @@
|
|||||||
name: The Workflow
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- script
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
ci:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
- name: Set up Bun
|
|
||||||
uses: oven-sh/setup-bun@v2
|
|
||||||
with:
|
|
||||||
bun-version: latest
|
|
||||||
- name: Install dependencies
|
|
||||||
run: bun install --frozen-lockfile
|
|
||||||
- name: Run test suite
|
|
||||||
run: bun test META.test.js workflow.test.js
|
|
||||||
|
|
||||||
run:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: ci
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
- name: Set up Bun
|
|
||||||
uses: oven-sh/setup-bun@v2
|
|
||||||
with:
|
|
||||||
bun-version: latest
|
|
||||||
- name: Install dependencies
|
|
||||||
run: bun install --frozen-lockfile
|
|
||||||
- name: Validate runnable scenarios
|
|
||||||
run: bun run run
|
|
||||||
|
|
||||||
purge-dns-cache:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: run
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
- name: Purge CDN cache
|
|
||||||
run: |
|
|
||||||
for file in $(ls); do
|
|
||||||
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@script/${file}"
|
|
||||||
done
|
|
||||||
|
|
||||||
generate-config:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: run
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
- name: Set up Bun
|
|
||||||
uses: oven-sh/setup-bun@v2
|
|
||||||
with:
|
|
||||||
bun-version: latest
|
|
||||||
- name: Install dependencies
|
|
||||||
run: bun install --frozen-lockfile
|
|
||||||
- name: Generate YAML configuration
|
|
||||||
run: |
|
|
||||||
mkdir -p publish
|
|
||||||
bun run generate
|
|
||||||
cat > publish/META.yaml << 'EOL'
|
|
||||||
proxy-providers-defaults: &ppd
|
|
||||||
type: http
|
|
||||||
interval: 86400
|
|
||||||
health-check:
|
|
||||||
enable: true
|
|
||||||
url: "https://www.gstatic.com/generate_204"
|
|
||||||
interval: 300
|
|
||||||
filter: "^(?!.*(群|邀请|返利|循环|官网|客服|网站|网址|获取|订阅|流量|到期|机场|下次|版本|官址|备用|过期|已用|联系|邮箱|工单|贩卖|通知|倒卖|防止|国内|地址|频道|无法|说明|使用|提示|特别|访问|支持|教程|关注|更新|作者|加入|USE|USED|TOTAL|EXPIRE|EMAIL|Panel|Channel|Author))"
|
|
||||||
proxy-providers:
|
|
||||||
Provider A:
|
|
||||||
<<: *ppd
|
|
||||||
url: "https://the.url.of/A.yaml"
|
|
||||||
override:
|
|
||||||
additional-prefix: "[A] "
|
|
||||||
Provider B:
|
|
||||||
<<: *ppd
|
|
||||||
url: "https://the.url.of/B.yaml"
|
|
||||||
override:
|
|
||||||
additional-prefix: "[B] "
|
|
||||||
Provider C:
|
|
||||||
<<: *ppd
|
|
||||||
url: "https://the.url.of/C.yaml"
|
|
||||||
override:
|
|
||||||
additional-prefix: "[C] "
|
|
||||||
EOL
|
|
||||||
cat META.yaml >> publish/META.yaml
|
|
||||||
- name: Push to config branch
|
|
||||||
run: |
|
|
||||||
cd publish
|
|
||||||
git init
|
|
||||||
git config --local user.name "github-actions[bot]"
|
|
||||||
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
||||||
git checkout -b config
|
|
||||||
git add .
|
|
||||||
git commit -m "Update YAML configuration"
|
|
||||||
git remote add origin "https://github-actions[bot]:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
|
|
||||||
git push -f origin config
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
node_modules/
|
|
||||||
META.yaml
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
const fs = require("node:fs");
|
|
||||||
const path = require("node:path");
|
|
||||||
const vm = require("node:vm");
|
|
||||||
const yaml = require("yaml");
|
|
||||||
|
|
||||||
function loadMain() {
|
|
||||||
const content = fs.readFileSync(path.join(__dirname, "META.js"), "utf8");
|
|
||||||
const wrapped = `${content}
|
|
||||||
|
|
||||||
module.exports = { main };`;
|
|
||||||
const context = {
|
|
||||||
module: { exports: {} },
|
|
||||||
console: {
|
|
||||||
log() {},
|
|
||||||
warn() {},
|
|
||||||
error() {},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
vm.runInNewContext(wrapped, context, { filename: "META.js" });
|
|
||||||
return context.module.exports.main;
|
|
||||||
}
|
|
||||||
|
|
||||||
function main() {
|
|
||||||
const generateConfig = loadMain();
|
|
||||||
const config = generateConfig({}, { skipValidation: true });
|
|
||||||
|
|
||||||
if (config.error) {
|
|
||||||
throw new Error(config.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(path.join(__dirname, "META.yaml"), yaml.stringify(config));
|
|
||||||
console.log("Generated META.yaml");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
main();
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error.message);
|
|
||||||
process.exitCode = 1;
|
|
||||||
}
|
|
||||||
@@ -1,791 +0,0 @@
|
|||||||
// from https://github.com/xixu-me/META
|
|
||||||
|
|
||||||
// ################################################### this section can be flexibly customized ###################################################
|
|
||||||
|
|
||||||
// Number of STATIC proxy groups (for IP-sensitive services)
|
|
||||||
const STATIC_PROXY_COUNT = 4;
|
|
||||||
|
|
||||||
// Routing rules are matched in order from top to bottom, with the rule at the top of the list taking precedence over the rules below it.
|
|
||||||
const services = [
|
|
||||||
// Media & Content
|
|
||||||
{ name: "bilibili", tld: "com" },
|
|
||||||
{ name: "Netflix", tld: "com" },
|
|
||||||
{ name: "YouTube", tld: "com" },
|
|
||||||
|
|
||||||
// AI/LLM Services
|
|
||||||
{ name: "Anthropic", tld: "com" },
|
|
||||||
{ name: "Arco", domain: "www.youware.com" },
|
|
||||||
{ name: "Gemini", tld: "google", alias: "Google-Gemini" },
|
|
||||||
{ name: "OpenAI", tld: "com" },
|
|
||||||
{ name: "xAI", tld: "ai", sld: "x" },
|
|
||||||
|
|
||||||
// Social Media & Communication
|
|
||||||
{ name: "Douyin", domain: "douyin.com", alias: "Douyin" },
|
|
||||||
{ name: "rednote", domain: "xiaohongshu.com", alias: "Xiaohongshu" },
|
|
||||||
{ name: "Telegram", tld: "org" },
|
|
||||||
{
|
|
||||||
name: "Truth Social",
|
|
||||||
tld: "com",
|
|
||||||
sld: "truthsocial",
|
|
||||||
alias: "TruthSocial",
|
|
||||||
},
|
|
||||||
{ name: "X", tld: "com" },
|
|
||||||
|
|
||||||
// Financial Services
|
|
||||||
{ name: "Binance", tld: "com" },
|
|
||||||
{ name: "Bybit", tld: "com" },
|
|
||||||
{ name: "OKX", tld: "com" },
|
|
||||||
|
|
||||||
// Technology Companies
|
|
||||||
{ name: "Apple", tld: "com" },
|
|
||||||
{ name: "Google", tld: "google", sld: "about" },
|
|
||||||
{ name: "Microsoft", tld: "com" },
|
|
||||||
|
|
||||||
// Infrastructure
|
|
||||||
{ name: "Speedtest", tld: "net" },
|
|
||||||
{ name: "Xget", domain: "xuc.xi-xu.me" },
|
|
||||||
{ name: "Cloudflare", tld: "com" },
|
|
||||||
];
|
|
||||||
|
|
||||||
const LOCATION_ICON_SET_URL = "https://img.icons8.com/color/144/";
|
|
||||||
|
|
||||||
const locations = [
|
|
||||||
{
|
|
||||||
name: "Argentina 🇦🇷",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}argentina`,
|
|
||||||
keywords: ["阿根廷", "Argentina"],
|
|
||||||
codes: ["ARG", "AR"],
|
|
||||||
emoji: ["🇦🇷"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Canada 🇨🇦",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}canada`,
|
|
||||||
keywords: ["加拿大", "Canada"],
|
|
||||||
codes: ["CAN", "CA"],
|
|
||||||
emoji: ["🇨🇦"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Finland 🇫🇮",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}finland`,
|
|
||||||
keywords: ["芬兰", "Finland"],
|
|
||||||
codes: ["FIN", "FI"],
|
|
||||||
emoji: ["🇫🇮"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "France 🇫🇷",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}france`,
|
|
||||||
keywords: ["法国", "France"],
|
|
||||||
codes: ["FR"],
|
|
||||||
emoji: ["🇫🇷"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Germany 🇩🇪",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}germany`,
|
|
||||||
keywords: ["德国", "Germany"],
|
|
||||||
codes: ["GER", "DE"],
|
|
||||||
emoji: ["🇩🇪"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Hong Kong, China 🇭🇰",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}hongkong-circular`,
|
|
||||||
keywords: ["香港", "Hong Kong"],
|
|
||||||
codes: ["HK"],
|
|
||||||
emoji: ["🇭🇰"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "India 🇮🇳",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}india`,
|
|
||||||
keywords: ["印度", "India"],
|
|
||||||
codes: ["IND", "IN"],
|
|
||||||
emoji: ["🇮🇳"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Iraq 🇮🇶",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}iraq`,
|
|
||||||
keywords: ["伊拉克", "Iraq"],
|
|
||||||
codes: ["IQ"],
|
|
||||||
emoji: ["🇮🇶"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Japan 🇯🇵",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}japan`,
|
|
||||||
keywords: ["日本", "Japan"],
|
|
||||||
codes: ["JP"],
|
|
||||||
emoji: ["🇯🇵"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Korea 🇰🇷",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}south-korea`,
|
|
||||||
keywords: ["韩国", "Korea"],
|
|
||||||
codes: ["KR"],
|
|
||||||
emoji: ["🇰🇷"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Russia 🇷🇺",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}russian-federation`,
|
|
||||||
keywords: ["俄罗斯", "Russia Federation", "Russia"],
|
|
||||||
codes: ["RU"],
|
|
||||||
emoji: ["🇷🇺"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Singapore 🇸🇬",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}singapore`,
|
|
||||||
keywords: ["新加坡", "Singapore"],
|
|
||||||
codes: ["SG"],
|
|
||||||
emoji: ["🇸🇬"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Taiwan, China 🇨🇳",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}china-circular`,
|
|
||||||
keywords: ["台湾", "Taiwan"],
|
|
||||||
codes: ["TW"],
|
|
||||||
emoji: ["🇹🇼"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Thailand 🇹🇭",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}thailand`,
|
|
||||||
keywords: ["泰国", "Thailand"],
|
|
||||||
codes: ["TH"],
|
|
||||||
emoji: ["🇹🇭"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Türkiye 🇹🇷",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}turkey`,
|
|
||||||
keywords: ["土耳其", "Türkiye", "Turkey"],
|
|
||||||
codes: ["TUR", "TR"],
|
|
||||||
emoji: ["🇹🇷"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Ukraine 🇺🇦",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}ukraine`,
|
|
||||||
keywords: ["乌克兰", "Ukraine"],
|
|
||||||
codes: ["UKR", "UA"],
|
|
||||||
emoji: ["🇺🇦"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "United Kingdom 🇬🇧",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}great-britain`,
|
|
||||||
keywords: ["英国", "United Kingdom", "Great Britain"],
|
|
||||||
codes: ["UK", "GB"],
|
|
||||||
emoji: ["🇬🇧"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "United States 🇺🇸",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}usa`,
|
|
||||||
keywords: ["美国", "United States of America", "United States"],
|
|
||||||
codes: ["USA", "US"],
|
|
||||||
emoji: ["🇺🇸"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Global 🌐",
|
|
||||||
icon: "https://img.icons8.com/?size=144&id=3685&format=png&color=7bbbe9",
|
|
||||||
keywords: ["Global", "Cloudflare"],
|
|
||||||
codes: ["GL", "CF"],
|
|
||||||
emoji: ["🌐"],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// ####################################### DO NOT MODIFY THE CODE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING #######################################
|
|
||||||
|
|
||||||
function extractFavicon(domain) {
|
|
||||||
return `https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://${domain}&size=128`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapeRegex(text) {
|
|
||||||
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildLocationFilter({ keywords = [], codes = [], emoji = [] }) {
|
|
||||||
const patterns = [
|
|
||||||
...keywords.map((keyword) => escapeRegex(keyword)),
|
|
||||||
...codes.map((code) => `\\b${escapeRegex(code)}\\b`),
|
|
||||||
...emoji.map((symbol) => escapeRegex(symbol)),
|
|
||||||
];
|
|
||||||
|
|
||||||
return `(?i)${patterns.join("|")}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
locations.forEach((location) => {
|
|
||||||
location.filter = buildLocationFilter(location);
|
|
||||||
});
|
|
||||||
|
|
||||||
// General Configuration
|
|
||||||
|
|
||||||
const generalConfig = {
|
|
||||||
"mixed-port": 7890,
|
|
||||||
"allow-lan": false,
|
|
||||||
mode: "rule",
|
|
||||||
"log-level": "info",
|
|
||||||
ipv6: true,
|
|
||||||
"find-process-mode": "strict",
|
|
||||||
profile: {
|
|
||||||
"store-selected": true,
|
|
||||||
"store-fake-ip": true,
|
|
||||||
},
|
|
||||||
"unified-delay": true,
|
|
||||||
"tcp-concurrent": true,
|
|
||||||
"global-ua": "\u0063\u006c\u0061\u0073\u0068.\u006D\u0065\u0074\u0061",
|
|
||||||
"etag-support": true,
|
|
||||||
};
|
|
||||||
|
|
||||||
// DNS
|
|
||||||
|
|
||||||
const chineseNameservers = [
|
|
||||||
"https://dns.alidns.com/dns-query",
|
|
||||||
"https://doh.pub/dns-query",
|
|
||||||
];
|
|
||||||
|
|
||||||
const internationalNameservers = [
|
|
||||||
"https://cloudflare-dns.com/dns-query",
|
|
||||||
"https://dns.google/dns-query",
|
|
||||||
// "https://dns.mullvad.net/dns-query",
|
|
||||||
// "https://wikimedia-dns.org/dns-query",
|
|
||||||
// "https://doh.dns.sb/dns-query",
|
|
||||||
];
|
|
||||||
|
|
||||||
const dns = {
|
|
||||||
enable: true,
|
|
||||||
"cache-algorithm": "arc",
|
|
||||||
"prefer-h3": false,
|
|
||||||
"use-hosts": true,
|
|
||||||
"use-system-hosts": false,
|
|
||||||
"respect-rules": true,
|
|
||||||
ipv6: true,
|
|
||||||
"enhanced-mode": "fake-ip",
|
|
||||||
"fake-ip-range": "198.18.0.1/16",
|
|
||||||
"fake-ip-range6": "fd00::/18",
|
|
||||||
"fake-ip-filter-mode": "blacklist",
|
|
||||||
"fake-ip-filter": [
|
|
||||||
"rule-set:fake-ip-filter",
|
|
||||||
"rule-set:direct",
|
|
||||||
"rule-set:private",
|
|
||||||
"rule-set:connectivity-check",
|
|
||||||
],
|
|
||||||
"default-nameserver": [
|
|
||||||
"tls://223.5.5.5",
|
|
||||||
"tls://223.6.6.6",
|
|
||||||
"tls://119.29.29.29",
|
|
||||||
],
|
|
||||||
"proxy-server-nameserver": chineseNameservers,
|
|
||||||
"nameserver-policy": {
|
|
||||||
"rule-set:private": ["system://"],
|
|
||||||
"rule-set:direct,geolocation-cn": chineseNameservers,
|
|
||||||
},
|
|
||||||
nameserver: internationalNameservers,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Hosts
|
|
||||||
|
|
||||||
const hosts = {};
|
|
||||||
|
|
||||||
// Domain Sniffing
|
|
||||||
|
|
||||||
const sniffer = {
|
|
||||||
enable: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
// TUN
|
|
||||||
|
|
||||||
const tun = {
|
|
||||||
enable: true,
|
|
||||||
stack: "mixed",
|
|
||||||
"auto-route": true,
|
|
||||||
"auto-detect-interface": true,
|
|
||||||
"strict-route": true,
|
|
||||||
"dns-hijack": ["any:53", "tcp://any:53"],
|
|
||||||
};
|
|
||||||
|
|
||||||
// Proxy Groups
|
|
||||||
|
|
||||||
const proxyGroupDefaults = {
|
|
||||||
url: "https://www.gstatic.com/generate_204",
|
|
||||||
interval: 300,
|
|
||||||
lazy: true,
|
|
||||||
timeout: 5000,
|
|
||||||
"max-failed-times": 5,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Generate STATIC proxy group names
|
|
||||||
function generateStaticProxyNames() {
|
|
||||||
if (STATIC_PROXY_COUNT === 1) {
|
|
||||||
return ["STATIC"];
|
|
||||||
}
|
|
||||||
return Array.from(
|
|
||||||
{ length: STATIC_PROXY_COUNT },
|
|
||||||
(_, i) => `STATIC-${i + 1}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const staticProxyNames = generateStaticProxyNames();
|
|
||||||
|
|
||||||
const serviceProxyGroupProxies = [
|
|
||||||
"PROXY",
|
|
||||||
...staticProxyNames,
|
|
||||||
"AUTO",
|
|
||||||
"DIRECT",
|
|
||||||
"Chinese Mainland 🇨🇳",
|
|
||||||
...locations.map(({ name }) => name),
|
|
||||||
];
|
|
||||||
|
|
||||||
const locationPolicyProxyGroupDefaults = {
|
|
||||||
...proxyGroupDefaults,
|
|
||||||
proxies: ["REJECT"],
|
|
||||||
"include-all": true,
|
|
||||||
};
|
|
||||||
|
|
||||||
const SERVICE_ICON_SET_URL =
|
|
||||||
"https://cdn.jsdelivr.net/gh/xixu-me/favicons@assets/favicons/";
|
|
||||||
|
|
||||||
function getServiceIcon(service) {
|
|
||||||
if (service.icon) return service.icon;
|
|
||||||
if (service.domain) return extractFavicon(service.domain);
|
|
||||||
if (service.tld) {
|
|
||||||
const secondLevelDomain = service.sld || service.name.toLowerCase();
|
|
||||||
return `${SERVICE_ICON_SET_URL}${secondLevelDomain}.${service.tld}.png`;
|
|
||||||
}
|
|
||||||
console.warn(`No icon configuration for service: ${service.name}`);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
services.forEach((service) => {
|
|
||||||
service.icon = getServiceIcon(service);
|
|
||||||
});
|
|
||||||
|
|
||||||
function generateServiceProxyGroups(items, defaultConfig) {
|
|
||||||
return items.map(({ name, icon }) => ({
|
|
||||||
...defaultConfig,
|
|
||||||
name,
|
|
||||||
icon,
|
|
||||||
type: "select",
|
|
||||||
proxies: serviceProxyGroupProxies,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateLocationPolicyProxyGroups(
|
|
||||||
items,
|
|
||||||
defaultConfig,
|
|
||||||
type,
|
|
||||||
extraProps = {},
|
|
||||||
) {
|
|
||||||
const getStrategyName = (type, strategy) => {
|
|
||||||
switch (type) {
|
|
||||||
case "url-test":
|
|
||||||
return "AUTO";
|
|
||||||
case "fallback":
|
|
||||||
return "FALLBACK";
|
|
||||||
case "load-balance":
|
|
||||||
switch (strategy) {
|
|
||||||
case "consistent-hashing":
|
|
||||||
return "LOAD BALANCING (consistent hashing)";
|
|
||||||
case "round-robin":
|
|
||||||
return "LOAD BALANCING (round-robin)";
|
|
||||||
case "sticky-sessions":
|
|
||||||
return "LOAD BALANCING (sticky sessions)";
|
|
||||||
default:
|
|
||||||
return "LOAD BALANCING";
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return type.toUpperCase();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return items.map(({ name, icon, filter }) => {
|
|
||||||
const strategyName = getStrategyName(type, extraProps.strategy);
|
|
||||||
const emoji = name.split(" ").pop();
|
|
||||||
const newName = `${strategyName} ${emoji}`;
|
|
||||||
return {
|
|
||||||
...defaultConfig,
|
|
||||||
name: newName,
|
|
||||||
type,
|
|
||||||
icon,
|
|
||||||
filter,
|
|
||||||
hidden: true,
|
|
||||||
...extraProps,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateLocationSelectProxyGroups() {
|
|
||||||
return locations.map(({ name, icon }) => ({
|
|
||||||
...proxyGroupDefaults,
|
|
||||||
name,
|
|
||||||
type: "select",
|
|
||||||
icon,
|
|
||||||
proxies: [
|
|
||||||
`LOAD BALANCING (consistent hashing) ${name.split(" ").pop()}`,
|
|
||||||
`LOAD BALANCING (round-robin) ${name.split(" ").pop()}`,
|
|
||||||
`LOAD BALANCING (sticky sessions) ${name.split(" ").pop()}`,
|
|
||||||
`FALLBACK ${name.split(" ").pop()}`,
|
|
||||||
`AUTO ${name.split(" ").pop()}`,
|
|
||||||
],
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
const BASE_ICON_SET_URL =
|
|
||||||
"https://cdn.jsdelivr.net/gh/Koolson/Qure@master/IconSet/Color/";
|
|
||||||
|
|
||||||
// Generate STATIC proxy groups
|
|
||||||
function generateStaticProxyGroups(defaultConfig) {
|
|
||||||
return staticProxyNames.map((name, index) => ({
|
|
||||||
...defaultConfig,
|
|
||||||
name,
|
|
||||||
type: "select",
|
|
||||||
"include-all": true,
|
|
||||||
icon: `${BASE_ICON_SET_URL}Static.png`,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
const proxyGroups = [
|
|
||||||
{
|
|
||||||
...proxyGroupDefaults,
|
|
||||||
name: "PROXY",
|
|
||||||
type: "select",
|
|
||||||
proxies: [
|
|
||||||
...staticProxyNames,
|
|
||||||
"AUTO",
|
|
||||||
"DIRECT",
|
|
||||||
"Chinese Mainland 🇨🇳",
|
|
||||||
...locations.map(({ name }) => name),
|
|
||||||
],
|
|
||||||
icon: `${BASE_ICON_SET_URL}Proxy.png`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...proxyGroupDefaults,
|
|
||||||
name: "AUTO",
|
|
||||||
type: "url-test",
|
|
||||||
tolerance: 50,
|
|
||||||
"include-all": true,
|
|
||||||
icon: `${BASE_ICON_SET_URL}Auto.png`,
|
|
||||||
hidden: true,
|
|
||||||
},
|
|
||||||
...generateStaticProxyGroups(proxyGroupDefaults),
|
|
||||||
...generateServiceProxyGroups(services, proxyGroupDefaults),
|
|
||||||
{
|
|
||||||
...proxyGroupDefaults,
|
|
||||||
name: "Domestic",
|
|
||||||
type: "select",
|
|
||||||
proxies: [
|
|
||||||
"DIRECT",
|
|
||||||
"PROXY",
|
|
||||||
...staticProxyNames,
|
|
||||||
"AUTO",
|
|
||||||
"Chinese Mainland 🇨🇳",
|
|
||||||
...locations.map(({ name }) => name),
|
|
||||||
],
|
|
||||||
icon: `${BASE_ICON_SET_URL}Domestic.png`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...proxyGroupDefaults,
|
|
||||||
name: "Others",
|
|
||||||
type: "select",
|
|
||||||
proxies: [...serviceProxyGroupProxies],
|
|
||||||
icon: `${BASE_ICON_SET_URL}Final.png`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...proxyGroupDefaults,
|
|
||||||
name: "Advertising",
|
|
||||||
type: "select",
|
|
||||||
proxies: ["REJECT", "DIRECT", ...staticProxyNames],
|
|
||||||
icon: `${BASE_ICON_SET_URL}Advertising.png`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...locationPolicyProxyGroupDefaults,
|
|
||||||
name: "Chinese Mainland 🇨🇳",
|
|
||||||
type: "select",
|
|
||||||
icon: `${LOCATION_ICON_SET_URL}china`,
|
|
||||||
proxies: ["REJECT"],
|
|
||||||
"include-all": true,
|
|
||||||
filter:
|
|
||||||
"(?i)\u5927\u9646|\u4e2d\u56fd|\u7535\u4fe1|\u79fb\u52a8|\u8054\u901a|Mainland|China|CN|mainland|china|cn|🇨🇳",
|
|
||||||
},
|
|
||||||
...generateLocationPolicyProxyGroups(
|
|
||||||
locations,
|
|
||||||
locationPolicyProxyGroupDefaults,
|
|
||||||
"url-test",
|
|
||||||
{
|
|
||||||
tolerance: 50,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
...generateLocationPolicyProxyGroups(
|
|
||||||
locations,
|
|
||||||
locationPolicyProxyGroupDefaults,
|
|
||||||
"fallback",
|
|
||||||
),
|
|
||||||
...generateLocationPolicyProxyGroups(
|
|
||||||
locations,
|
|
||||||
locationPolicyProxyGroupDefaults,
|
|
||||||
"load-balance",
|
|
||||||
{
|
|
||||||
strategy: "round-robin",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
...generateLocationPolicyProxyGroups(
|
|
||||||
locations,
|
|
||||||
locationPolicyProxyGroupDefaults,
|
|
||||||
"load-balance",
|
|
||||||
{
|
|
||||||
strategy: "consistent-hashing",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
...generateLocationPolicyProxyGroups(
|
|
||||||
locations,
|
|
||||||
locationPolicyProxyGroupDefaults,
|
|
||||||
"load-balance",
|
|
||||||
{
|
|
||||||
strategy: "sticky-sessions",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
...generateLocationSelectProxyGroups(),
|
|
||||||
];
|
|
||||||
|
|
||||||
// Routing Rules
|
|
||||||
|
|
||||||
function generateServiceRules(services) {
|
|
||||||
return services.map(
|
|
||||||
({ name }) => `RULE-SET,${name.toLowerCase().replace(/\s+/g, "")},${name}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const rules = [
|
|
||||||
"RULE-SET,applications,DIRECT",
|
|
||||||
"RULE-SET,win-phonelink,DIRECT",
|
|
||||||
"RULE-SET,lancidr,DIRECT,no-resolve",
|
|
||||||
"RULE-SET,private,DIRECT",
|
|
||||||
...generateServiceRules(services),
|
|
||||||
"RULE-SET,reject,Advertising",
|
|
||||||
"RULE-SET,win-spy,Advertising",
|
|
||||||
"RULE-SET,direct,Domestic",
|
|
||||||
"RULE-SET,proxy,PROXY",
|
|
||||||
"RULE-SET,telegramcidr,Telegram",
|
|
||||||
"RULE-SET,xcidr,X",
|
|
||||||
"RULE-SET,googlecidr,Google",
|
|
||||||
"RULE-SET,cloudflarecidr,Cloudflare",
|
|
||||||
"RULE-SET,cncidr,Domestic",
|
|
||||||
"MATCH,Others",
|
|
||||||
];
|
|
||||||
|
|
||||||
// Rule Providers
|
|
||||||
|
|
||||||
const ruleProviderDefaults = {
|
|
||||||
type: "http",
|
|
||||||
interval: 14400,
|
|
||||||
};
|
|
||||||
|
|
||||||
function generateServiceRuleProviders(services, defaultConfig) {
|
|
||||||
return services.reduce((acc, { name, alias }) => {
|
|
||||||
const fileName = (alias || name).toLowerCase();
|
|
||||||
const ruleName = name.toLowerCase().replace(/\s+/g, "");
|
|
||||||
acc[ruleName] = {
|
|
||||||
...defaultConfig,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "domain",
|
|
||||||
url: `https://cdn.jsdelivr.net/gh/xixu-me/RFM@universal/${fileName}.mrs`,
|
|
||||||
path: `./rulesets/${ruleName}.mrs`,
|
|
||||||
};
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
const ruleProviders = {
|
|
||||||
"fake-ip-filter": {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "domain",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/fake-ip-filter.mrs",
|
|
||||||
path: "./rulesets/fake-ip-filter.mrs",
|
|
||||||
},
|
|
||||||
"connectivity-check": {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "domain",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@universal/connectivity-check.mrs",
|
|
||||||
path: "./rulesets/connectivity-check.mrs",
|
|
||||||
},
|
|
||||||
applications: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "yaml",
|
|
||||||
behavior: "classical",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/applications.yaml",
|
|
||||||
path: "./rulesets/applications.yaml",
|
|
||||||
},
|
|
||||||
"win-phonelink": {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "yaml",
|
|
||||||
behavior: "classical",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@fixed/win-phonelink.yaml",
|
|
||||||
path: "./rulesets/win-phonelink.yaml",
|
|
||||||
},
|
|
||||||
lancidr: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "ipcidr",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/lancidr.mrs",
|
|
||||||
path: "./rulesets/lancidr.mrs",
|
|
||||||
},
|
|
||||||
cncidr: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "ipcidr",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/cncidr.mrs",
|
|
||||||
path: "./rulesets/cncidr.mrs",
|
|
||||||
},
|
|
||||||
cloudflarecidr: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "ipcidr",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/cloudflarecidr.mrs",
|
|
||||||
path: "./rulesets/cloudflarecidr.mrs",
|
|
||||||
},
|
|
||||||
googlecidr: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "ipcidr",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/googlecidr.mrs",
|
|
||||||
path: "./rulesets/googlecidr.mrs",
|
|
||||||
},
|
|
||||||
telegramcidr: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "ipcidr",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/telegramcidr.mrs",
|
|
||||||
path: "./rulesets/telegramcidr.mrs",
|
|
||||||
},
|
|
||||||
xcidr: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "ipcidr",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/xcidr.mrs",
|
|
||||||
path: "./rulesets/xcidr.mrs",
|
|
||||||
},
|
|
||||||
private: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "domain",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/private.mrs",
|
|
||||||
path: "./rulesets/private.mrs",
|
|
||||||
},
|
|
||||||
direct: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "domain",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/direct.mrs",
|
|
||||||
path: "./rulesets/direct.mrs",
|
|
||||||
},
|
|
||||||
proxy: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "domain",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/proxy.mrs",
|
|
||||||
path: "./rulesets/proxy.mrs",
|
|
||||||
},
|
|
||||||
"geolocation-cn": {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "domain",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@universal/geolocation-cn.mrs",
|
|
||||||
path: "./rulesets/geolocation-cn.mrs",
|
|
||||||
},
|
|
||||||
reject: {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "domain",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@basic/reject.mrs",
|
|
||||||
path: "./rulesets/reject.mrs",
|
|
||||||
},
|
|
||||||
"win-spy": {
|
|
||||||
...ruleProviderDefaults,
|
|
||||||
format: "mrs",
|
|
||||||
behavior: "domain",
|
|
||||||
url: "https://cdn.jsdelivr.net/gh/xixu-me/RFM@universal/win-spy.mrs",
|
|
||||||
path: "./rulesets/win-spy.mrs",
|
|
||||||
},
|
|
||||||
...generateServiceRuleProviders(services, ruleProviderDefaults),
|
|
||||||
};
|
|
||||||
|
|
||||||
// generate configuration using the above settings
|
|
||||||
|
|
||||||
function validateOriginalConfig(config) {
|
|
||||||
if (!config)
|
|
||||||
throw new Error("Configuration object cannot be null or undefined");
|
|
||||||
const proxyCount = Array.isArray(config.proxies) ? config.proxies.length : 0;
|
|
||||||
const proxyProviderCount = Object.keys(
|
|
||||||
config["proxy-providers"] || {},
|
|
||||||
).length;
|
|
||||||
if (proxyCount === 0 && proxyProviderCount === 0)
|
|
||||||
throw new Error(
|
|
||||||
"The original configuration must contain a non-empty proxies array (see https://wiki.\u006D\u0065\u0074\u0061\u0063\u0075\u0062\u0065\u0078.one/en/config/proxies/) or a proxy-providers object with at least one property (see https://wiki.\u006D\u0065\u0074\u0061\u0063\u0075\u0062\u0065\u0078.one/en/config/proxy-providers/)",
|
|
||||||
);
|
|
||||||
if (proxyCount > 0) {
|
|
||||||
const proxiesWithoutRemoteEndpoint = new Set([
|
|
||||||
"direct",
|
|
||||||
"dns",
|
|
||||||
"pass",
|
|
||||||
"reject",
|
|
||||||
]);
|
|
||||||
|
|
||||||
config.proxies.forEach((proxy, index) => {
|
|
||||||
if (!proxy.name || !proxy.type) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid proxy number ${
|
|
||||||
index + 1
|
|
||||||
} configuration (see https://wiki.\u006D\u0065\u0074\u0061\u0063\u0075\u0062\u0065\u0078.one/en/config/proxies/)`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
!proxiesWithoutRemoteEndpoint.has(String(proxy.type).toLowerCase()) &&
|
|
||||||
(!proxy.server || proxy.port == null)
|
|
||||||
) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid proxy number ${
|
|
||||||
index + 1
|
|
||||||
} configuration (see https://wiki.\u006D\u0065\u0074\u0061\u0063\u0075\u0062\u0065\u0078.one/en/config/proxies/)`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(
|
|
||||||
`The original configuration contains ${proxyCount} proxies, which will be preserved`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (proxyProviderCount > 0) {
|
|
||||||
Object.entries(config["proxy-providers"]).forEach(
|
|
||||||
([name, provider], index) => {
|
|
||||||
if (!provider.type || (provider.type === "http" && !provider.url)) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid proxy provider number ${
|
|
||||||
index + 1
|
|
||||||
} configuration (see https://wiki.\u006D\u0065\u0074\u0061\u0063\u0075\u0062\u0065\u0078.one/en/config/proxy-providers/)`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
console.log(
|
|
||||||
`The original configuration contains ${proxyProviderCount} proxy providers, which will be preserved`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function main(config, options = {}) {
|
|
||||||
try {
|
|
||||||
if (!options.skipValidation) {
|
|
||||||
validateOriginalConfig(config);
|
|
||||||
}
|
|
||||||
Object.assign(config, generalConfig, {
|
|
||||||
dns,
|
|
||||||
hosts,
|
|
||||||
sniffer,
|
|
||||||
tun,
|
|
||||||
"proxy-groups": proxyGroups,
|
|
||||||
rules,
|
|
||||||
"rule-providers": ruleProviders,
|
|
||||||
});
|
|
||||||
console.log("The generated configuration is as follows");
|
|
||||||
console.log(config);
|
|
||||||
return config;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(
|
|
||||||
`An error occurred during configuration generation: ${error.message}`,
|
|
||||||
);
|
|
||||||
return { error: error.message, originalConfig: config };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-89
@@ -1,89 +0,0 @@
|
|||||||
const fs = require("node:fs");
|
|
||||||
const path = require("node:path");
|
|
||||||
const vm = require("node:vm");
|
|
||||||
|
|
||||||
function loadMetaModule() {
|
|
||||||
const content = fs.readFileSync(path.join(__dirname, "META.js"), "utf8");
|
|
||||||
const wrapped = `${content}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
main,
|
|
||||||
validateOriginalConfig,
|
|
||||||
};`;
|
|
||||||
|
|
||||||
const context = {
|
|
||||||
module: { exports: {} },
|
|
||||||
console: {
|
|
||||||
log() {},
|
|
||||||
warn() {},
|
|
||||||
error() {},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
vm.runInNewContext(wrapped, context, { filename: "META.js" });
|
|
||||||
return context.module.exports;
|
|
||||||
}
|
|
||||||
|
|
||||||
function assert(condition, message) {
|
|
||||||
if (!condition) {
|
|
||||||
throw new Error(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function runScenario(name, input, options) {
|
|
||||||
const { main } = loadMetaModule();
|
|
||||||
const config = main(structuredClone(input), options);
|
|
||||||
|
|
||||||
assert(!config.error, `${name}: ${config.error}`);
|
|
||||||
assert(Array.isArray(config.rules), `${name}: rules should be an array`);
|
|
||||||
assert(
|
|
||||||
Array.isArray(config["proxy-groups"]),
|
|
||||||
`${name}: proxy-groups should be an array`
|
|
||||||
);
|
|
||||||
assert(
|
|
||||||
config["rule-providers"] && typeof config["rule-providers"] === "object",
|
|
||||||
`${name}: rule-providers should be present`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function main() {
|
|
||||||
runScenario(
|
|
||||||
"proxy-based config",
|
|
||||||
{
|
|
||||||
proxies: [
|
|
||||||
{
|
|
||||||
name: "sample",
|
|
||||||
type: "socks5",
|
|
||||||
server: "127.0.0.1",
|
|
||||||
port: 1080,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
|
|
||||||
runScenario(
|
|
||||||
"provider-based config",
|
|
||||||
{
|
|
||||||
"proxy-providers": {
|
|
||||||
provider: {
|
|
||||||
type: "http",
|
|
||||||
url: "https://example.com/provider.yaml",
|
|
||||||
path: "./providers/provider.yaml",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
|
|
||||||
runScenario("publish generation", {}, { skipValidation: true });
|
|
||||||
|
|
||||||
console.log("Validated META.js against 3 scenarios.");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
main();
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error.message);
|
|
||||||
process.exitCode = 1;
|
|
||||||
}
|
|
||||||
-117
@@ -1,117 +0,0 @@
|
|||||||
const test = require("node:test");
|
|
||||||
const assert = require("node:assert/strict");
|
|
||||||
const fs = require("node:fs");
|
|
||||||
const path = require("node:path");
|
|
||||||
const vm = require("node:vm");
|
|
||||||
|
|
||||||
const repoRoot = __dirname;
|
|
||||||
|
|
||||||
function loadMetaModule() {
|
|
||||||
const content = fs.readFileSync(path.join(repoRoot, "META.js"), "utf8");
|
|
||||||
const wrapped = `${content}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
locations,
|
|
||||||
generalConfig,
|
|
||||||
tun,
|
|
||||||
main,
|
|
||||||
validateOriginalConfig,
|
|
||||||
};`;
|
|
||||||
|
|
||||||
const context = {
|
|
||||||
module: { exports: {} },
|
|
||||||
console: {
|
|
||||||
log() {},
|
|
||||||
warn() {},
|
|
||||||
error() {},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
vm.runInNewContext(wrapped, context, { filename: "META.js" });
|
|
||||||
return context.module.exports;
|
|
||||||
}
|
|
||||||
|
|
||||||
function mihomoRegex(source) {
|
|
||||||
return new RegExp(source.replace(/^\(\?i\)/, ""), "i");
|
|
||||||
}
|
|
||||||
|
|
||||||
test("validateOriginalConfig accepts mihomo dns outbound proxies", () => {
|
|
||||||
const { validateOriginalConfig } = loadMetaModule();
|
|
||||||
|
|
||||||
assert.doesNotThrow(() =>
|
|
||||||
validateOriginalConfig({
|
|
||||||
proxies: [{ name: "dns-out", type: "dns" }],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("generated config does not force deprecated global fingerprinting", () => {
|
|
||||||
const { main } = loadMetaModule();
|
|
||||||
|
|
||||||
const config = main({
|
|
||||||
proxies: [
|
|
||||||
{
|
|
||||||
name: "sample",
|
|
||||||
type: "socks5",
|
|
||||||
server: "127.0.0.1",
|
|
||||||
port: 1080,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(config["global-client-fingerprint"], undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("main can skip source validation for publish-time generation", () => {
|
|
||||||
const { main } = loadMetaModule();
|
|
||||||
|
|
||||||
const config = main({}, { skipValidation: true });
|
|
||||||
|
|
||||||
assert.equal(config.error, undefined);
|
|
||||||
assert.ok(Array.isArray(config.rules));
|
|
||||||
assert.ok(Array.isArray(config["proxy-groups"]));
|
|
||||||
});
|
|
||||||
|
|
||||||
test("generated tun config fully replaces the source tun settings", () => {
|
|
||||||
const { main } = loadMetaModule();
|
|
||||||
|
|
||||||
const config = main({
|
|
||||||
proxies: [
|
|
||||||
{
|
|
||||||
name: "sample",
|
|
||||||
type: "socks5",
|
|
||||||
server: "127.0.0.1",
|
|
||||||
port: 1080,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
tun: {
|
|
||||||
enable: false,
|
|
||||||
"auto-route": false,
|
|
||||||
"auto-redirect": true,
|
|
||||||
mtu: 9000,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.deepEqual(JSON.parse(JSON.stringify(config.tun)), {
|
|
||||||
enable: true,
|
|
||||||
stack: "mixed",
|
|
||||||
"auto-route": true,
|
|
||||||
"auto-detect-interface": true,
|
|
||||||
"strict-route": true,
|
|
||||||
"dns-hijack": ["any:53", "tcp://any:53"],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test("location filters avoid matching unrelated country names", () => {
|
|
||||||
const { locations } = loadMetaModule();
|
|
||||||
|
|
||||||
const india = locations.find((location) => location.name === "India 🇮🇳");
|
|
||||||
const canada = locations.find((location) => location.name === "Canada 🇨🇦");
|
|
||||||
|
|
||||||
assert.ok(india, "India location should exist");
|
|
||||||
assert.ok(canada, "Canada location should exist");
|
|
||||||
|
|
||||||
assert.equal(mihomoRegex(india.filter).test("Argentina 01"), false);
|
|
||||||
assert.equal(mihomoRegex(india.filter).test("Finland-IEPL"), false);
|
|
||||||
assert.equal(mihomoRegex(canada.filter).test("Singapore-Anycast"), false);
|
|
||||||
});
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"lockfileVersion": 1,
|
|
||||||
"configVersion": 0,
|
|
||||||
"workspaces": {
|
|
||||||
"": {
|
|
||||||
"name": "meta",
|
|
||||||
"dependencies": {
|
|
||||||
"yaml": "^2.8.1",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"packages": {
|
|
||||||
"yaml": ["yaml@2.8.3", "", { "bin": "bin.mjs" }, "sha512-AvbaCLOO2Otw/lW5bmh9d/WEdcDFdQp2Z2ZUH3pX9U2ihyUY0nvLv7J6TrWowklRGPYbB/IuIMfYgxaCPg5Bpg=="],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
[install]
|
|
||||||
auto = "disable"
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "meta",
|
|
||||||
"private": true,
|
|
||||||
"scripts": {
|
|
||||||
"generate": "bun META.generate.js",
|
|
||||||
"test": "bun test META.test.js workflow.test.js",
|
|
||||||
"run": "bun META.run.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"yaml": "^2.8.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
const test = require("node:test");
|
|
||||||
const assert = require("node:assert/strict");
|
|
||||||
const fs = require("node:fs");
|
|
||||||
const path = require("node:path");
|
|
||||||
const childProcess = require("node:child_process");
|
|
||||||
|
|
||||||
const repoRoot = __dirname;
|
|
||||||
const workflowPath = path.join(repoRoot, ".github", "workflows", "run.yml");
|
|
||||||
const runScriptPath = path.join(repoRoot, "META.run.js");
|
|
||||||
|
|
||||||
function runBun(args) {
|
|
||||||
return childProcess.spawnSync("bun", args, {
|
|
||||||
cwd: repoRoot,
|
|
||||||
encoding: "utf8",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensureDependenciesInstalled() {
|
|
||||||
const result = runBun(["install", "--frozen-lockfile"]);
|
|
||||||
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
test("workflow runs CI before run and publish jobs", () => {
|
|
||||||
const workflow = fs.readFileSync(workflowPath, "utf8");
|
|
||||||
|
|
||||||
assert.match(workflow, /^ ci:\s*$/m, "workflow should define a ci job");
|
|
||||||
assert.match(
|
|
||||||
workflow,
|
|
||||||
/uses:\s+oven-sh\/setup-bun@v2/,
|
|
||||||
"workflow should install Bun via the official setup action"
|
|
||||||
);
|
|
||||||
assert.match(
|
|
||||||
workflow,
|
|
||||||
/^ run:\s*$(?:\r?\n)(?:\s+.*\r?\n)*?\s+needs:\s+ci\s*$/m,
|
|
||||||
"run job should depend on ci"
|
|
||||||
);
|
|
||||||
assert.match(
|
|
||||||
workflow,
|
|
||||||
/^ purge-dns-cache:\s*$(?:\r?\n)(?:\s+.*\r?\n)*?\s+needs:\s+run\s*$/m,
|
|
||||||
"purge-dns-cache should depend on run"
|
|
||||||
);
|
|
||||||
assert.match(
|
|
||||||
workflow,
|
|
||||||
/^ generate-config:\s*$(?:\r?\n)(?:\s+.*\r?\n)*?\s+needs:\s+run\s*$/m,
|
|
||||||
"generate-config should depend on run"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("workflow installs dependencies and runs tests in ci job", () => {
|
|
||||||
const workflow = fs.readFileSync(workflowPath, "utf8");
|
|
||||||
|
|
||||||
assert.match(
|
|
||||||
workflow,
|
|
||||||
/bun install --frozen-lockfile/,
|
|
||||||
"ci job should install dependencies with Bun"
|
|
||||||
);
|
|
||||||
assert.match(workflow, /bun test/, "ci job should run the test suite with Bun");
|
|
||||||
assert.match(workflow, /bun run run/, "run job should use Bun scripts");
|
|
||||||
assert.match(
|
|
||||||
workflow,
|
|
||||||
/bun run generate/,
|
|
||||||
"generate-config job should use Bun scripts"
|
|
||||||
);
|
|
||||||
assert.doesNotMatch(
|
|
||||||
workflow,
|
|
||||||
/sed -i .*validateOriginalConfig/,
|
|
||||||
"workflow should not mutate META.js to bypass validation"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("META.run.js executes the generator against sample inputs", () => {
|
|
||||||
const result = runBun([runScriptPath]);
|
|
||||||
|
|
||||||
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
||||||
assert.match(
|
|
||||||
result.stdout,
|
|
||||||
/validated/i,
|
|
||||||
"run script should report successful validation"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("META.generate.js creates YAML output without mutating source", () => {
|
|
||||||
const outputPath = path.join(repoRoot, "META.yaml");
|
|
||||||
fs.rmSync(outputPath, { force: true });
|
|
||||||
ensureDependenciesInstalled();
|
|
||||||
|
|
||||||
const result = runBun(["META.generate.js"]);
|
|
||||||
|
|
||||||
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
||||||
assert.ok(fs.existsSync(outputPath), "generate script should create META.yaml");
|
|
||||||
assert.match(
|
|
||||||
fs.readFileSync(outputPath, "utf8"),
|
|
||||||
/mixed-port:\s*7890/,
|
|
||||||
"generated YAML should include core config values"
|
|
||||||
);
|
|
||||||
|
|
||||||
fs.rmSync(outputPath, { force: true });
|
|
||||||
});
|
|
||||||
Reference in new issue
Block a user