From 683138a85c66d8887d322377821a4b4eaf8ed9a3 Mon Sep 17 00:00:00 2001 From: Hamy Date: Fri, 6 Mar 2026 04:05:46 +0500 Subject: [PATCH] fix --- mod.ts | 29 ++++++++++++++--------------- proxy.ts | 3 +++ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/mod.ts b/mod.ts index 7249a38..bf50fa2 100644 --- a/mod.ts +++ b/mod.ts @@ -9,7 +9,7 @@ import { serve } from "https://deno.land/std@0.208.0/http/server.ts"; import { YTMusic, YouTubeSearch, LastFM, fetchFromPiped, fetchFromInvidious, getLyrics, getTrendingMusic, getRadio, getTopArtists, getTopTracks, getArtistInfo, getTrackInfo, getSongComplete, getAlbumComplete, getArtistComplete, getFullChain } from "./lib.ts"; import { html as uiHtml } from "./ui.ts"; -import { installProxyFetch, loadProxyConfig, saveProxyConfig, setRuntimeProxy, getActiveProxyUrl } from "./proxy.ts"; +import { installProxyFetch, loadProxyConfig, saveProxyConfig, setRuntimeProxy, getActiveProxyUrl, nativeFetch } from "./proxy.ts"; // ── Proxy: load saved config → install (patch globalThis.fetch) ───────────── await loadProxyConfig(); @@ -143,23 +143,22 @@ async function handler(req: Request): Promise { if (ipRes.ok) { ipInfo = await ipRes.json(); ip = ipInfo.ip || "unknown"; } } catch { /* failed */ } - // 2. Прямой IP (нативный fetch, минуя прокси-патч) - let directIp = ip; // если прокси не настроен — они совпадут + // 2. Прямой IP — через nativeFetch (всегда обходит прокси-патч) + let directIp: string | null = null; if (proxyActive) { try { - // Импортируем нативный fetch через тот же модуль - const { proxyFetch: _pf, ...rest } = await import("./proxy.ts"); - void rest; void _pf; - // Используем глобальный нативный fetch напрямую через eval-трюк - const nf = (globalThis as any)._nativeFetchRef; - if (nf) { - const r = await nf("https://api.ipify.org?format=json"); - if (r.ok) { const d = await r.json(); directIp = d.ip || ip; } - } - } catch { /* ignore */ } + const r = await nativeFetch("https://api.ipify.org?format=json"); + if (r.ok) { const d = await r.json(); directIp = d.ip || null; } + } catch { /* ignore — direct connection may also be blocked */ } } - const proxyWorking = proxyActive && ip !== "unknown" && ip !== directIp; + // Proxy is "working" if: + // - proxy is configured + // - we got a response through it (ip != unknown) + // - AND either: direct IP differs, OR we couldn't get direct IP at all + const ipChanged = directIp !== null && directIp !== ip; + const cantReachDirect = directIp === null; + const proxyWorking = proxyActive && ip !== "unknown" && (ipChanged || cantReachDirect); return json({ proxy_enabled: proxyActive, @@ -167,7 +166,7 @@ async function handler(req: Request): Promise { proxy_url: mask(activeProxy), current_ip: ip, direct_ip: directIp, - ip_masked: ip !== directIp, + ip_masked: ipChanged, latency_ms: latencyMs, location: ipInfo.city ? `${ipInfo.city}, ${ipInfo.region}, ${ipInfo.country}` : (ipInfo.country || null), org: ipInfo.org || null, diff --git a/proxy.ts b/proxy.ts index d0221ea..f1f0dbd 100644 --- a/proxy.ts +++ b/proxy.ts @@ -17,6 +17,9 @@ // Must be module-level so it's captured at import time. const _nativeFetch: typeof fetch = globalThis.fetch.bind(globalThis); +/** Direct (non-proxied) fetch — always bypasses the proxy. Use for IP comparison. */ +export const nativeFetch: typeof fetch = _nativeFetch; + // ─── Runtime proxy config (set via API / UI) ───────────────────────────────── let _runtimeProxyUrl: string | null = null;