Добавлен статус в интерфейс

This commit is contained in:
2026-03-06 03:50:00 +05:00
parent 307b8c809b
commit 7444e7ddd7
2 changed files with 176 additions and 1 deletions

64
mod.ts
View File

@@ -98,6 +98,70 @@ async function handler(req: Request): Promise<Response> {
if (pathname === "/favicon.ico") return new Response(null, { status: 204 });
if (pathname === "/health") return json({ status: "ok" });
// ============ PROXY STATUS ============
if (pathname === "/api/proxy/status") {
const httpsProxy = Deno.env.get("HTTPS_PROXY") || Deno.env.get("https_proxy");
const httpProxy = Deno.env.get("HTTP_PROXY") || Deno.env.get("http_proxy");
const proxyUrl = Deno.env.get("PROXY_URL");
const proxyActive = !!(httpsProxy || httpProxy || proxyUrl);
const mask = (u: string | undefined) =>
u ? u.replace(/:\/\/[^@]*@/, "://<hidden>@") : null;
// 1. Определяем текущий внешний IP (через прокси, если настроен)
let ip = "unknown";
let ipInfo: Record<string, string> = {};
let latencyMs = -1;
try {
const t0 = Date.now();
const ipRes = await fetch("https://ipinfo.io/json", {
headers: { "User-Agent": "curl/7.88.0", "Accept": "application/json" },
signal: AbortSignal.timeout(8000),
});
latencyMs = Date.now() - t0;
if (ipRes.ok) {
ipInfo = await ipRes.json();
ip = ipInfo.ip || "unknown";
}
} catch { /* timeout or connection error */ }
// 2. Определяем IP без прокси (прямое соединение), чтобы сравнить
let directIp = "unknown";
try {
// Временно вызываем нативный fetch напрямую, минуя патч
const nativeFetch: typeof fetch = (globalThis as any).__nativeFetch || fetch;
const res = await nativeFetch("https://api.ipify.org?format=json", {
signal: AbortSignal.timeout(5000),
});
if (res.ok) {
const data = await res.json();
directIp = data.ip || "unknown";
}
} catch { /* ignore */ }
const proxyWorking = proxyActive && ip !== "unknown" && ip !== directIp;
return json({
proxy_enabled: proxyActive,
proxy_working: proxyWorking,
proxy_url: mask((httpsProxy || httpProxy || proxyUrl) || undefined),
current_ip: ip,
direct_ip: directIp,
ip_masked: directIp !== "unknown" && ip !== directIp,
latency_ms: latencyMs,
location: ipInfo.city
? `${ipInfo.city}, ${ipInfo.region}, ${ipInfo.country}`
: (ipInfo.country || null),
org: ipInfo.org || null,
timezone: ipInfo.timezone || null,
status: proxyActive
? (proxyWorking ? "proxy_ok" : (ip === "unknown" ? "proxy_error" : "proxy_transparent"))
: "no_proxy",
});
}
// ============ PROXY CONFIG ============
if (pathname === "/api/proxy/config") {