Dew-OF-Aurora 6 giorni fa
parent
commit
5bc14f7543
1 ha cambiato i file con 17 aggiunte e 16 eliminazioni
  1. 17 16
      substore/operator_template.js

+ 17 - 16
substore/operator_template.js

@@ -6,7 +6,7 @@
 
 
 const ROUTER_VALUE_JSON_URL = "http://192.168.50.1:8080/current_ip.json";
 const ROUTER_VALUE_JSON_URL = "http://192.168.50.1:8080/current_ip.json";
 const SERVER_VALUE_JSON_URL = "https://git.dewofaurora.de/aurora/vmess-domain-rotator/raw/runtime-state/runtime/current_domain.json";
 const SERVER_VALUE_JSON_URL = "https://git.dewofaurora.de/aurora/vmess-domain-rotator/raw/runtime-state/runtime/current_domain.json";
-const ROUTER_MIN_SPEED_MBPS = 5;
+const ROUTER_MIN_SPEED_MB_PER_S = 5;
 
 
 const NODE_NAME_REGEX = /(argo|cf|vm|优选)/i;
 const NODE_NAME_REGEX = /(argo|cf|vm|优选)/i;
 const CACHE_KEY = "vmess-domain-rotator:current";
 const CACHE_KEY = "vmess-domain-rotator:current";
@@ -52,61 +52,62 @@ function extractValue(obj, sourceName) {
   return value;
   return value;
 }
 }
 
 
-function parseRouterSpeedMbps(routerObj) {
+function parseRouterSpeedMBps(routerObj) {
   const raw = String(routerObj?.top_candidates?.[0]?.download_speed || "").trim();
   const raw = String(routerObj?.top_candidates?.[0]?.download_speed || "").trim();
   if (!raw) {
   if (!raw) {
-    return { mbps: null, raw: "", status: "missing", unit: "" };
+    return { mbPerSec: null, raw: "", status: "missing", unit: "" };
   }
   }
 
 
   const normalized = raw.toLowerCase().replace(/\s+/g, "");
   const normalized = raw.toLowerCase().replace(/\s+/g, "");
   const match = normalized.match(/([0-9]+(?:\.[0-9]+)?)/);
   const match = normalized.match(/([0-9]+(?:\.[0-9]+)?)/);
   if (!match) {
   if (!match) {
-    return { mbps: null, raw, status: "invalid", unit: "" };
+    return { mbPerSec: null, raw, status: "invalid", unit: "" };
   }
   }
 
 
   const numeric = Number(match[1]);
   const numeric = Number(match[1]);
   if (!Number.isFinite(numeric) || numeric < 0) {
   if (!Number.isFinite(numeric) || numeric < 0) {
-    return { mbps: null, raw, status: "invalid", unit: "" };
+    return { mbPerSec: null, raw, status: "invalid", unit: "" };
   }
   }
 
 
-  let mbps = numeric;
+  let mbPerSec = numeric;
   let unit = "unknown";
   let unit = "unknown";
 
 
   if (normalized.includes("gb/s") || normalized.includes("g/s") || normalized.endsWith("gb") || normalized.endsWith("g")) {
   if (normalized.includes("gb/s") || normalized.includes("g/s") || normalized.endsWith("gb") || normalized.endsWith("g")) {
-    mbps = numeric * 1024;
+    mbPerSec = numeric * 1024;
     unit = "gb/s";
     unit = "gb/s";
   } else if (normalized.includes("mb/s") || normalized.includes("m/s") || normalized.endsWith("mb") || normalized.endsWith("m")) {
   } else if (normalized.includes("mb/s") || normalized.includes("m/s") || normalized.endsWith("mb") || normalized.endsWith("m")) {
-    mbps = numeric;
+    mbPerSec = numeric;
     unit = "mb/s";
     unit = "mb/s";
   } else if (normalized.includes("kb/s") || normalized.includes("k/s") || normalized.endsWith("kb") || normalized.endsWith("k")) {
   } else if (normalized.includes("kb/s") || normalized.includes("k/s") || normalized.endsWith("kb") || normalized.endsWith("k")) {
-    mbps = numeric / 1024;
+    mbPerSec = numeric / 1024;
     unit = "kb/s";
     unit = "kb/s";
   } else if (normalized.includes("b/s")) {
   } else if (normalized.includes("b/s")) {
-    mbps = numeric / (1024 * 1024);
+    mbPerSec = numeric / (1024 * 1024);
     unit = "b/s";
     unit = "b/s";
   }
   }
 
 
   const status = unit === "unknown" ? "unknown_unit" : "ok";
   const status = unit === "unknown" ? "unknown_unit" : "ok";
-  return { mbps, raw, status, unit };
+  return { mbPerSec, raw, status, unit };
 }
 }
 
 
+
 async function selectValueRouterFirst() {
 async function selectValueRouterFirst() {
   const telemetry = {
   const telemetry = {
-    router: { ok: false, value: "", status: "", sourceType: "", error: "", speedRaw: "", speedMbps: null, speedParse: "missing", speedUnit: "" },
+    router: { ok: false, value: "", status: "", sourceType: "", error: "", speedRaw: "", speedMBps: null, speedParse: "missing", speedUnit: "" },
     server: { ok: false, value: "", status: "", sourceType: "", error: "" }
     server: { ok: false, value: "", status: "", sourceType: "", error: "" }
   };
   };
 
 
   try {
   try {
     const routerObj = await fetchRuntimeJson(ROUTER_VALUE_JSON_URL, "router");
     const routerObj = await fetchRuntimeJson(ROUTER_VALUE_JSON_URL, "router");
     const routerValue = extractValue(routerObj, "router");
     const routerValue = extractValue(routerObj, "router");
-    const speed = parseRouterSpeedMbps(routerObj);
+    const speed = parseRouterSpeedMBps(routerObj);
 
 
     telemetry.router.ok = true;
     telemetry.router.ok = true;
     telemetry.router.value = routerValue;
     telemetry.router.value = routerValue;
     telemetry.router.status = String(routerObj?.status || "");
     telemetry.router.status = String(routerObj?.status || "");
     telemetry.router.sourceType = String(routerObj?.source_type || "");
     telemetry.router.sourceType = String(routerObj?.source_type || "");
     telemetry.router.speedRaw = speed.raw;
     telemetry.router.speedRaw = speed.raw;
-    telemetry.router.speedMbps = speed.mbps;
+    telemetry.router.speedMBps = speed.mbPerSec;
     telemetry.router.speedParse = speed.status;
     telemetry.router.speedParse = speed.status;
     telemetry.router.speedUnit = speed.unit;
     telemetry.router.speedUnit = speed.unit;
   } catch (e) {
   } catch (e) {
@@ -137,7 +138,7 @@ async function selectValueRouterFirst() {
     return { value: telemetry.router.value, chosenSource: "router", reason: "server_fail", telemetry };
     return { value: telemetry.router.value, chosenSource: "router", reason: "server_fail", telemetry };
   }
   }
 
 
-  if (telemetry.router.speedParse === "ok" && telemetry.router.speedMbps < ROUTER_MIN_SPEED_MBPS) {
+  if (telemetry.router.speedParse === "ok" && telemetry.router.speedMBps < ROUTER_MIN_SPEED_MB_PER_S) {
     return { value: telemetry.server.value, chosenSource: "server", reason: "router_low_speed", telemetry };
     return { value: telemetry.server.value, chosenSource: "server", reason: "router_low_speed", telemetry };
   }
   }
 
 
@@ -174,7 +175,7 @@ async function operator(proxies = [], targetPlatform, context) {
   if (decision) {
   if (decision) {
     const t = decision.telemetry;
     const t = decision.telemetry;
     console.log(
     console.log(
-      `[vmess-domain-rotator] chosen=${decision.chosenSource}, reason=${decision.reason}, router_status=${t.router.status || "n/a"}, server_status=${t.server.status || "n/a"}, router_speed_raw=${t.router.speedRaw || "n/a"}, router_speed_mbps=${t.router.speedMbps == null ? "n/a" : t.router.speedMbps.toFixed(3)}, speed_parse=${t.router.speedParse}, threshold_mbps=${ROUTER_MIN_SPEED_MBPS}, value=${value}, updated=${updated}, total=${proxies.length}, target=${targetPlatform}`
+      `[vmess-domain-rotator] chosen=${decision.chosenSource}, reason=${decision.reason}, router_status=${t.router.status || "n/a"}, server_status=${t.server.status || "n/a"}, router_speed_raw=${t.router.speedRaw || "n/a"}, router_speed_mb_per_s=${t.router.speedMBps == null ? "n/a" : t.router.speedMBps.toFixed(3)}, speed_parse=${t.router.speedParse}, threshold_mb_per_s=${ROUTER_MIN_SPEED_MB_PER_S}, value=${value}, updated=${updated}, total=${proxies.length}, target=${targetPlatform}`
     );
     );
   } else {
   } else {
     console.log(`[vmess-domain-rotator] chosen=cache, value=${value}, updated=${updated}, total=${proxies.length}, target=${targetPlatform}`);
     console.log(`[vmess-domain-rotator] chosen=cache, value=${value}, updated=${updated}, total=${proxies.length}, target=${targetPlatform}`);