/* Sub-Store operator (production-friendly) - Pull dynamic domain from your current_domain.json - Replace vmess server field for matched nodes */ const DOMAIN_JSON_URL = "https://git.dewofaurora.de/aurora/vmess-domain-rotator/raw/main/runtime/current_domain.json"; const NODE_NAME_REGEX = /(argo|cf|vm|优选)/i; const CACHE_KEY = "vmess-domain-rotator:current"; const CACHE_TTL_MS = 5 * 60 * 1000; async function fetchDomainViaSubStore() { const $ = $substore; const { body, statusCode } = await $.http.get({ url: DOMAIN_JSON_URL, headers: { Accept: "application/json", "Cache-Control": "no-cache" }, timeout: 5000 }); if (statusCode < 200 || statusCode >= 300) { throw new Error(`http status ${statusCode}`); } const obj = JSON.parse(body || "{}"); const domain = String(obj.domain || "").trim().toLowerCase(); if (!domain) { throw new Error("empty domain field"); } return domain; } async function operator(proxies = [], targetPlatform, context) { const cache = scriptResourceCache; let domain = cache.get(CACHE_KEY); if (!domain) { try { domain = await fetchDomainViaSubStore(); cache.set(CACHE_KEY, domain, CACHE_TTL_MS); } catch (e) { console.log(`[vmess-domain-rotator] fetch failed: ${e.message}`); return proxies; } } let updated = 0; for (const p of proxies) { if (!p || p.type !== "vmess") continue; if (!NODE_NAME_REGEX.test(p.name || "")) continue; if (p.server !== domain) { p.server = domain; updated += 1; } } console.log(`[vmess-domain-rotator] domain=${domain}, updated=${updated}, total=${proxies.length}, target=${targetPlatform}`); return proxies; }