forked from github-mirror/Verome-API
fix
This commit is contained in:
29
mod.ts
29
mod.ts
@@ -9,7 +9,7 @@
|
|||||||
import { serve } from "https://deno.land/std@0.208.0/http/server.ts";
|
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 { 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 { 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) ─────────────
|
// ── Proxy: load saved config → install (patch globalThis.fetch) ─────────────
|
||||||
await loadProxyConfig();
|
await loadProxyConfig();
|
||||||
@@ -143,23 +143,22 @@ async function handler(req: Request): Promise<Response> {
|
|||||||
if (ipRes.ok) { ipInfo = await ipRes.json(); ip = ipInfo.ip || "unknown"; }
|
if (ipRes.ok) { ipInfo = await ipRes.json(); ip = ipInfo.ip || "unknown"; }
|
||||||
} catch { /* failed */ }
|
} catch { /* failed */ }
|
||||||
|
|
||||||
// 2. Прямой IP (нативный fetch, минуя прокси-патч)
|
// 2. Прямой IP — через nativeFetch (всегда обходит прокси-патч)
|
||||||
let directIp = ip; // если прокси не настроен — они совпадут
|
let directIp: string | null = null;
|
||||||
if (proxyActive) {
|
if (proxyActive) {
|
||||||
try {
|
try {
|
||||||
// Импортируем нативный fetch через тот же модуль
|
const r = await nativeFetch("https://api.ipify.org?format=json");
|
||||||
const { proxyFetch: _pf, ...rest } = await import("./proxy.ts");
|
if (r.ok) { const d = await r.json(); directIp = d.ip || null; }
|
||||||
void rest; void _pf;
|
} catch { /* ignore — direct connection may also be blocked */ }
|
||||||
// Используем глобальный нативный 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 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({
|
return json({
|
||||||
proxy_enabled: proxyActive,
|
proxy_enabled: proxyActive,
|
||||||
@@ -167,7 +166,7 @@ async function handler(req: Request): Promise<Response> {
|
|||||||
proxy_url: mask(activeProxy),
|
proxy_url: mask(activeProxy),
|
||||||
current_ip: ip,
|
current_ip: ip,
|
||||||
direct_ip: directIp,
|
direct_ip: directIp,
|
||||||
ip_masked: ip !== directIp,
|
ip_masked: ipChanged,
|
||||||
latency_ms: latencyMs,
|
latency_ms: latencyMs,
|
||||||
location: ipInfo.city ? `${ipInfo.city}, ${ipInfo.region}, ${ipInfo.country}` : (ipInfo.country || null),
|
location: ipInfo.city ? `${ipInfo.city}, ${ipInfo.region}, ${ipInfo.country}` : (ipInfo.country || null),
|
||||||
org: ipInfo.org || null,
|
org: ipInfo.org || null,
|
||||||
|
|||||||
3
proxy.ts
3
proxy.ts
@@ -17,6 +17,9 @@
|
|||||||
// Must be module-level so it's captured at import time.
|
// Must be module-level so it's captured at import time.
|
||||||
const _nativeFetch: typeof fetch = globalThis.fetch.bind(globalThis);
|
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) ─────────────────────────────────
|
// ─── Runtime proxy config (set via API / UI) ─────────────────────────────────
|
||||||
let _runtimeProxyUrl: string | null = null;
|
let _runtimeProxyUrl: string | null = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user