Elffuss BraidHub

kikocis/osiris public

09d1cb3093e4 · 2.8 KiBRawPermalink
1import type { CctvCamera } from './types';
2
3const IPCAMLIVE_API_SECRET = process.env.IPCAMLIVE_API_SECRET || '';
4
5const ATTiki_ODOS_CAMERAS = [
6 { alias: 'cam128', name: 'I/C D. Plakentias', city: 'Athens', lat: 38.0208, lng: 23.8578 },
7 { alias: 'cam231', name: 'I/C Papagou', city: 'Athens', lat: 37.9906, lng: 23.7947 },
8];
9
10const GREECE_REGIONAL_CAMERAS: CctvCamera[] = [
11 {
12 id: 'gr-thessaloniki-center-live',
13 lat: 40.6401, lng: 22.9444,
14 name: 'Thessaloniki – Center (live)', city: 'Thessaloniki', country: 'Greece',
15 stream_url: 'https://www.youtube.com/embed/7V0IRFbzRFI?autoplay=1&mute=1',
16 stream_type: 'iframe',
17 external_url: 'https://www.webcameras.gr/loc_wc/webcameras.asp?ID=510&lang=en',
18 source: 'meteothes.gr',
19 },
20 {
21 id: 'gr-kavala-live',
22 lat: 40.939, lng: 24.408,
23 name: 'Kavala – City View (live)', city: 'Kavala', country: 'Greece',
24 stream_url: 'https://city-view-of-kavala.click2stream.com/',
25 stream_type: 'iframe',
26 external_url: 'https://www.webcameras.gr/loc_wc/webcameras.asp?ID=286&lang=en',
27 source: 'click2stream',
28 },
29];
30
31async function fetchIpcamLiveHls(alias: string): Promise<string | null> {
32 try {
33 const res = await fetch(`https://ipcamlive.com/api/v2/getstreamhlsurl?apisecret=${IPCAMLIVE_API_SECRET}&alias=${alias}`, { signal: AbortSignal.timeout(5000) });
34 const data = await res.json();
35 return data.result === 'ok' ? String(data.data.url).replace(/^http:\/\//i, 'https://') : null;
36 } catch { return null; }
37}
38
39async function fetchIpcamLiveSnapshot(alias: string): Promise<string | null> {
40 try {
41 const res = await fetch(`https://ipcamlive.com/api/v2/getsnapshoturl?apisecret=${IPCAMLIVE_API_SECRET}&alias=${alias}`, { signal: AbortSignal.timeout(5000) });
42 const data = await res.json();
43 return data.result === 'ok' ? String(data.data.url).replace(/^http:\/\//i, 'https://') : null;
44 } catch { return null; }
45}
46
47export async function fetchGreeceCameras(): Promise<CctvCamera[]> {
48 const attikiSettled = await Promise.allSettled(
49 ATTiki_ODOS_CAMERAS.map(async (cam) => {
50 const hls = await fetchIpcamLiveHls(cam.alias);
51 const snapshot = await fetchIpcamLiveSnapshot(cam.alias);
52 return {
53 id: `gr-aodos-${cam.alias}`,
54 lat: cam.lat, lng: cam.lng,
55 name: cam.name, city: cam.city, country: 'Greece',
56 stream_url: hls || undefined,
57 stream_type: hls ? 'hls' : undefined,
58 feed_url: snapshot || `https://www.aodos.gr/wp-content/themes/aodos/assets/img/cameras/${cam.alias}-snapshot.jpg`,
59 source: 'Attiki Odos',
60 } as CctvCamera;
61 })
62 );
63
64 const attiki = attikiSettled.filter((r): r is PromiseFulfilledResult<CctvCamera> => r.status === 'fulfilled').map((r) => r.value);
65 return [...attiki, ...GREECE_REGIONAL_CAMERAS];
66}