| 1 | import { CctvCamera } from "./types"; |
| 2 | |
| 3 | export async function fetchAustraliaCameras(): Promise<CctvCamera[]> { |
| 4 | try { |
| 5 | const res = await fetch('https://www.livetraffic.com/datajson/all-feeds-web.json', { signal: AbortSignal.timeout(12000) }); |
| 6 | if (!res.ok) return []; |
| 7 | const data = await res.json(); |
| 8 | return (data || []).filter((event: { eventType: string; }) => event.eventType === 'liveCams').map((cam: { path: string; geometry: { coordinates: number[] }; properties: { title: string; region: string; href: string }; }) => { |
| 9 | return { |
| 10 | id: cam.path, |
| 11 | lat: cam.geometry.coordinates[1], |
| 12 | lng: cam.geometry.coordinates[0], |
| 13 | name: cam.properties.title || 'Australia Camera', |
| 14 | city: cam.properties.region || 'Australia', |
| 15 | country: 'Australia', |
| 16 | feed_url: cam.properties.href || '', |
| 17 | source: 'Live Traffic', |
| 18 | |
| 19 | }; |
| 20 | }).filter((c: { lat: number; lng: number; }) => c.lat && c.lng); |
| 21 | } catch { return []; } |
| 22 | } |