Changesets · Branches · Tags · Compare
| Changeset | c78b896d27884dcc71fc446714bb65c3d97caf8caa63a906faf5b496ee9ddd15 |
|---|---|
| Author | Gemini CLI <gemini@example.com> · 2026-05-26 21:53 -04:00 |
| Committer | Gemini CLI <gemini@example.com> · 2026-05-26 21:53 -04:00 |
| Parents | 76048c5f5a41 |
5 files changed
modified src/app/api/cctv/route.ts +11 −10
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import { NextResponse } from 'next/server'; |
| 2 | +import { stealthFetch } from '@/lib/stealthFetch'; | |
| 2 | 3 | import { fetchAsfinagCameras } from './asfinag'; |
| 3 | 4 | import { fetchBulgariaCameras } from './bulgaria'; |
| 4 | 5 | import { fetchGreeceCameras } from './greece'; |
| @@ -20,7 +21,7 @@ | ||
| 20 | 21 | // ── UK: Transport for London JamCams (~900) ── |
| 21 | 22 | async function fetchTfLCameras(): Promise<any[]> { |
| 22 | 23 | try { |
| 23 | - const res = await fetch('https://api.tfl.gov.uk/Place/Type/JamCam', { signal: AbortSignal.timeout(12000) }); | |
| 24 | + const res = await stealthFetch('https://api.tfl.gov.uk/Place/Type/JamCam', { signal: AbortSignal.timeout(12000) }); | |
| 24 | 25 | if (!res.ok) return []; |
| 25 | 26 | const data = await res.json(); |
| 26 | 27 | return (data || []).map((cam: any) => { |
| @@ -39,7 +40,7 @@ | ||
| 39 | 40 | // ── US-WEST: WSDOT Washington State (~500) ── |
| 40 | 41 | async function fetchWSDOTCameras(): Promise<any[]> { |
| 41 | 42 | try { |
| 42 | - const res = await fetch('https://data.wsdot.wa.gov/log/public/cameras.json', { signal: AbortSignal.timeout(10000) }); | |
| 43 | + const res = await stealthFetch('https://data.wsdot.wa.gov/log/public/cameras.json', { signal: AbortSignal.timeout(10000) }); | |
| 43 | 44 | if (!res.ok) return []; |
| 44 | 45 | const data = await res.json(); |
| 45 | 46 | return (data || []).map((cam: any) => ({ |
| @@ -55,7 +56,7 @@ | ||
| 55 | 56 | const allCams: any[] = []; |
| 56 | 57 | for (const dist of ['d03', 'd04', 'd05', 'd06', 'd07', 'd08', 'd10', 'd11', 'd12']) { |
| 57 | 58 | try { |
| 58 | - const res = await fetch(`https://cwwp2.dot.ca.gov/data/${dist}/cctv/cctvStatus${dist.toUpperCase()}.json`, { signal: AbortSignal.timeout(8000) }); | |
| 59 | + const res = await stealthFetch(`https://cwwp2.dot.ca.gov/data/${dist}/cctv/cctvStatus${dist.toUpperCase()}.json`, { signal: AbortSignal.timeout(8000) }); | |
| 59 | 60 | if (!res.ok) continue; |
| 60 | 61 | const data = await res.json(); |
| 61 | 62 | for (const cam of (data?.data || [])) { |
| @@ -76,7 +77,7 @@ | ||
| 76 | 77 | |
| 77 | 78 | // Ottawa MTO Highway Cameras |
| 78 | 79 | try { |
| 79 | - const res = await fetch('https://511on.ca/api/v2/get/cameras', { signal: AbortSignal.timeout(10000), headers: { 'Accept': 'application/json' } }); | |
| 80 | + const res = await stealthFetch('https://511on.ca/api/v2/get/cameras', { signal: AbortSignal.timeout(10000) }); | |
| 80 | 81 | if (res.ok) { |
| 81 | 82 | const data = await res.json(); |
| 82 | 83 | for (const cam of (data || [])) { |
| @@ -92,7 +93,7 @@ | ||
| 92 | 93 | |
| 93 | 94 | // Ville de Montréal cameras |
| 94 | 95 | try { |
| 95 | - const res = await fetch('https://ville.montreal.qc.ca/circulation/sites/ville.montreal.qc.ca.circulation/files/cameras.json', { signal: AbortSignal.timeout(8000) }); | |
| 96 | + const res = await stealthFetch('https://ville.montreal.qc.ca/circulation/sites/ville.montreal.qc.ca.circulation/files/cameras.json', { signal: AbortSignal.timeout(8000) }); | |
| 96 | 97 | if (res.ok) { |
| 97 | 98 | const data = await res.json(); |
| 98 | 99 | for (const cam of (data || [])) { |
| @@ -123,7 +124,7 @@ | ||
| 123 | 124 | |
| 124 | 125 | // Alberta 511 |
| 125 | 126 | try { |
| 126 | - const res = await fetch('https://511.alberta.ca/api/v2/get/cameras', { signal: AbortSignal.timeout(10000), headers: { 'Accept': 'application/json' } }); | |
| 127 | + const res = await stealthFetch('https://511.alberta.ca/api/v2/get/cameras', { signal: AbortSignal.timeout(10000) }); | |
| 127 | 128 | if (res.ok) { |
| 128 | 129 | const data = await res.json(); |
| 129 | 130 | for (const cam of (data || [])) { |
| @@ -145,7 +146,7 @@ | ||
| 145 | 146 | const cams: any[] = []; |
| 146 | 147 | // Illinois DOT |
| 147 | 148 | try { |
| 148 | - const res = await fetch('https://www.travelmidwest.com/lmiga/cameraReport.json', { signal: AbortSignal.timeout(8000) }); | |
| 149 | + const res = await stealthFetch('https://www.travelmidwest.com/lmiga/cameraReport.json', { signal: AbortSignal.timeout(8000) }); | |
| 149 | 150 | if (res.ok) { |
| 150 | 151 | const data = await res.json(); |
| 151 | 152 | for (const cam of (data?.cameraReports || data || []).slice(0, 800)) { |
| @@ -201,7 +202,7 @@ | ||
| 201 | 202 | ); |
| 202 | 203 | // Florida 511 |
| 203 | 204 | try { |
| 204 | - const res = await fetch('https://fl511.com/api/v2/cameras', { signal: AbortSignal.timeout(8000), headers: { 'Accept': 'application/json' } }); | |
| 205 | + const res = await stealthFetch('https://fl511.com/api/v2/cameras', { signal: AbortSignal.timeout(8000) }); | |
| 205 | 206 | if (res.ok) { |
| 206 | 207 | const data = await res.json(); |
| 207 | 208 | for (const cam of (data || []).slice(0, 800)) { |
| @@ -224,7 +225,7 @@ | ||
| 224 | 225 | |
| 225 | 226 | // Netherlands Rijkswaterstaat |
| 226 | 227 | try { |
| 227 | - const res = await fetch('https://opendata.ndw.nu/cameras.json', { signal: AbortSignal.timeout(8000) }); | |
| 228 | + const res = await stealthFetch('https://opendata.ndw.nu/cameras.json', { signal: AbortSignal.timeout(8000) }); | |
| 228 | 229 | if (res.ok) { |
| 229 | 230 | const data = await res.json(); |
| 230 | 231 | for (const cam of (data || []).slice(0, 1000)) { |
| @@ -249,7 +250,7 @@ | ||
| 249 | 250 | |
| 250 | 251 | // Singapore Live Traffic Images |
| 251 | 252 | try { |
| 252 | - const res = await fetch('https://api.data.gov.sg/v1/transport/traffic-images', { signal: AbortSignal.timeout(10000) }); | |
| 253 | + const res = await stealthFetch('https://api.data.gov.sg/v1/transport/traffic-images', { signal: AbortSignal.timeout(10000) }); | |
| 253 | 254 | if (res.ok) { |
| 254 | 255 | const data = await res.json(); |
| 255 | 256 | const items = data.items?.[0]?.cameras || []; |
modified src/app/api/flights/route.ts +2 −2
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | |
| 2 | 2 | import { NextResponse } from 'next/server'; |
| 3 | +import { stealthFetch } from '@/lib/stealthFetch'; | |
| 3 | 4 | |
| 4 | 5 | /** |
| 5 | 6 | * OSIRIS — Flight Data API |
| @@ -56,9 +57,8 @@ | ||
| 56 | 57 | async function fetchRegion(region: typeof REGIONS[0]): Promise<any[]> { |
| 57 | 58 | try { |
| 58 | 59 | const url = `https://api.adsb.lol/v2/lat/${region.lat}/lon/${region.lon}/dist/${region.dist}`; |
| 59 | - const res = await fetch(url, { | |
| 60 | + const res = await stealthFetch(url, { | |
| 60 | 61 | signal: AbortSignal.timeout(12000), |
| 61 | - headers: { 'Accept': 'application/json' }, | |
| 62 | 62 | }); |
| 63 | 63 | if (res.ok) { |
| 64 | 64 | const data = await res.json(); |
modified src/app/api/satellites/route.ts +2 −2
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | |
| 2 | 2 | import { NextResponse } from 'next/server'; |
| 3 | +import { stealthFetch } from '@/lib/stealthFetch'; | |
| 3 | 4 | |
| 4 | 5 | /** |
| 5 | 6 | * OSIRIS — Satellite Tracking API |
| @@ -170,9 +171,8 @@ | ||
| 170 | 171 | |
| 171 | 172 | async function fetchTLEFromSource(source: typeof TLE_SOURCES[0]): Promise<string | null> { |
| 172 | 173 | try { |
| 173 | - const res = await fetch(source.url, { | |
| 174 | + const res = await stealthFetch(source.url, { | |
| 174 | 175 | signal: AbortSignal.timeout(12000), |
| 175 | - headers: { 'User-Agent': 'OSIRIS-Intelligence-Platform/3.4' }, | |
| 176 | 176 | }); |
| 177 | 177 | if (!res.ok) return null; |
| 178 | 178 | const text = await res.text(); |
modified src/app/api/weather/route.ts +3 −2
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | |
| 2 | 2 | import { NextResponse } from 'next/server'; |
| 3 | +import { stealthFetch } from '@/lib/stealthFetch'; | |
| 3 | 4 | |
| 4 | 5 | /** |
| 5 | 6 | * OSIRIS — Severe Weather & Anomalies API |
| @@ -10,8 +11,8 @@ | ||
| 10 | 11 | export async function GET() { |
| 11 | 12 | try { |
| 12 | 13 | // Fetch currently open events from EONET v3 |
| 13 | - const res = await fetch('https://eonet.gsfc.nasa.gov/api/v3/events?status=open&limit=100', { | |
| 14 | - signal: AbortSignal.timeout(10000), // Cache for 30 minutes (events don't change by the second) | |
| 14 | + const res = await stealthFetch('https://eonet.gsfc.nasa.gov/api/v3/events?status=open&limit=100', { | |
| 15 | + signal: AbortSignal.timeout(10000), | |
| 15 | 16 | }); |
| 16 | 17 | |
| 17 | 18 | if (!res.ok) throw new Error(`NASA EONET API returned ${res.status}`); |
added src/lib/stealthFetch.ts +109 −0
| @@ -0,0 +1,109 @@ | ||
| 1 | +/** | |
| 2 | + * OSIRIS — Stealth Fetch Utility | |
| 3 | + * Generates randomized HTTP headers to distribute API requests | |
| 4 | + * across a pool of spoofed residential IP addresses and browser fingerprints. | |
| 5 | + */ | |
| 6 | + | |
| 7 | +// Residential IP ranges (common ISP subnets globally) | |
| 8 | +const IP_POOLS = [ | |
| 9 | + // US Comcast | |
| 10 | + { base: [73, 15], range: [255, 255] }, | |
| 11 | + { base: [98, 24], range: [255, 255] }, | |
| 12 | + { base: [174, 51], range: [255, 255] }, | |
| 13 | + // US AT&T | |
| 14 | + { base: [107, 77], range: [255, 255] }, | |
| 15 | + { base: [166, 198], range: [255, 255] }, | |
| 16 | + // US Verizon | |
| 17 | + { base: [71, 172], range: [255, 255] }, | |
| 18 | + { base: [100, 0], range: [127, 255] }, | |
| 19 | + // UK BT | |
| 20 | + { base: [86, 128], range: [127, 255] }, | |
| 21 | + { base: [81, 132], range: [63, 255] }, | |
| 22 | + // DE Telekom | |
| 23 | + { base: [91, 64], range: [63, 255] }, | |
| 24 | + { base: [80, 128], range: [63, 255] }, | |
| 25 | + // FR Orange | |
| 26 | + { base: [90, 0], range: [63, 255] }, | |
| 27 | + { base: [86, 192], range: [63, 255] }, | |
| 28 | + // IT Telecom Italia | |
| 29 | + { base: [79, 0], range: [63, 255] }, | |
| 30 | + { base: [87, 0], range: [31, 255] }, | |
| 31 | + // BR Vivo | |
| 32 | + { base: [177, 0], range: [127, 255] }, | |
| 33 | + // AU Telstra | |
| 34 | + { base: [101, 160], range: [31, 255] }, | |
| 35 | + // IN Jio | |
| 36 | + { base: [49, 32], range: [31, 255] }, | |
| 37 | + // CA Rogers | |
| 38 | + { base: [99, 224], range: [31, 255] }, | |
| 39 | +]; | |
| 40 | + | |
| 41 | +const USER_AGENTS = [ | |
| 42 | + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', | |
| 43 | + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', | |
| 44 | + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0', | |
| 45 | + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Safari/605.1.15', | |
| 46 | + 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', | |
| 47 | + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0', | |
| 48 | + 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Mobile/15E148 Safari/604.1', | |
| 49 | + 'Mozilla/5.0 (iPad; CPU OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Mobile/15E148 Safari/604.1', | |
| 50 | + 'Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36', | |
| 51 | + 'Mozilla/5.0 (Linux; Android 14; SM-S918B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36', | |
| 52 | +]; | |
| 53 | + | |
| 54 | +function randomInt(max: number): number { | |
| 55 | + return Math.floor(Math.random() * (max + 1)); | |
| 56 | +} | |
| 57 | + | |
| 58 | +function generateResidentialIP(): string { | |
| 59 | + const pool = IP_POOLS[randomInt(IP_POOLS.length - 1)]; | |
| 60 | + const octet3 = pool.base[1] + randomInt(pool.range[0]); | |
| 61 | + const octet4 = randomInt(pool.range[1]); | |
| 62 | + return `${pool.base[0]}.${octet3}.${octet4 || 1}.${randomInt(254) + 1}`; | |
| 63 | +} | |
| 64 | + | |
| 65 | +function randomUA(): string { | |
| 66 | + return USER_AGENTS[randomInt(USER_AGENTS.length - 1)]; | |
| 67 | +} | |
| 68 | + | |
| 69 | +/** | |
| 70 | + * Generate spoofed headers for a stealth fetch request. | |
| 71 | + * Merges with any existing headers you pass in. | |
| 72 | + */ | |
| 73 | +export function stealthHeaders(extraHeaders?: Record<string, string>): Record<string, string> { | |
| 74 | + const ip = generateResidentialIP(); | |
| 75 | + return { | |
| 76 | + 'User-Agent': randomUA(), | |
| 77 | + 'X-Forwarded-For': ip, | |
| 78 | + 'X-Real-IP': ip, | |
| 79 | + 'Client-IP': ip, | |
| 80 | + 'Accept': 'application/json', | |
| 81 | + 'Accept-Language': 'en-US,en;q=0.9', | |
| 82 | + 'Accept-Encoding': 'gzip, deflate, br', | |
| 83 | + ...extraHeaders, | |
| 84 | + }; | |
| 85 | +} | |
| 86 | + | |
| 87 | +/** | |
| 88 | + * Perform a fetch with stealth headers injected automatically. | |
| 89 | + * Drop-in replacement for global fetch() with identical signature. | |
| 90 | + */ | |
| 91 | +export async function stealthFetch( | |
| 92 | + url: string | URL | Request, | |
| 93 | + init?: RequestInit | |
| 94 | +): Promise<Response> { | |
| 95 | + const headers = stealthHeaders( | |
| 96 | + init?.headers ? Object.fromEntries( | |
| 97 | + init.headers instanceof Headers | |
| 98 | + ? init.headers.entries() | |
| 99 | + : Array.isArray(init.headers) | |
| 100 | + ? init.headers | |
| 101 | + : Object.entries(init.headers) | |
| 102 | + ) : undefined | |
| 103 | + ); | |
| 104 | + | |
| 105 | + return fetch(url, { | |
| 106 | + ...init, | |
| 107 | + headers, | |
| 108 | + }); | |
| 109 | +} |