This commit is contained in:
2026-03-06 04:05:46 +05:00
parent ed1f3b3a75
commit 683138a85c
2 changed files with 17 additions and 15 deletions

29
mod.ts
View File

@@ -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<Response> {
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<Response> {
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,