From a51d130b86308db1c5c70a97bc4e0cda1679ac24 Mon Sep 17 00:00:00 2001 From: kim Date: Sun, 18 Oct 2026 21:46:19 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B5=90=ED=86=B5=20CCTV:=20=EA=B3=A0=EC=86=8D?= =?UTF-8?q?=EB=8F=84=EB=A1=9C(type=3Dex)=EB=8F=84=20=ED=95=A8=EA=BB=98=20?= =?UTF-8?q?=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0=20=E2=80=94=20=EA=B5=AD?= =?UTF-8?q?=EB=8F=84(its)=EB=A7=8C=20=EB=B6=88=EB=9F=AC=20=EC=9D=B8?= =?UTF-8?q?=EC=B2=9C=EC=9D=B4=205=EA=B0=9C=EB=BF=90=EC=9D=B4=EB=8D=98=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C(=ED=95=A9=EC=B9=98=EB=A9=B4=20117=EA=B0=9C);?= =?UTF-8?q?=20=ED=83=AD=20=EC=9D=B4=EB=A6=84=20'=EA=B3=A0=EC=86=8D?= =?UTF-8?q?=EB=8F=84=EB=A1=9C=C2=B7=EA=B5=AD=EB=8F=84'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- src/gateway/routes/routes-misc.ts | 30 +++++++++++++++++++++++++----- web-ui/html/traffic-app.html | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/gateway/routes/routes-misc.ts b/src/gateway/routes/routes-misc.ts index 29915e8..2f6034b 100644 --- a/src/gateway/routes/routes-misc.ts +++ b/src/gateway/routes/routes-misc.ts @@ -161,13 +161,33 @@ export function registerMiscRoutes(app: express.Application, deps: MiscRouteDeps if (!apiKey) { res.status(503).json({ error: 'Traffic API key not configured' }); return; } const { minX = '124.0', maxX = '132.0', minY = '33.0', maxY = '39.0', cctvType = '1' } = req.query as Record; - const url = `https://openapi.its.go.kr:9443/cctvInfo?apiKey=${encodeURIComponent(apiKey)}&type=its&cctvType=${cctvType}&minX=${minX}&maxX=${maxX}&minY=${minY}&maxY=${maxY}&getType=json`; + // ITS 국가교통정보는 type=its(국도)와 type=ex(한국도로공사 고속도로)가 따로다. 예전엔 its만 불러서 + // 고속도로 CCTV가 통째로 빠졌다(인천 5개 → its+ex 117개). 기본은 둘 다, type=its|ex로 하나만도 가능. + const want = String((req.query as Record).type || 'all'); + const types = want === 'its' ? ['its'] : want === 'ex' ? ['ex'] : ['its', 'ex']; + const fetchType = async (type: string): Promise => { + const url = `https://openapi.its.go.kr:9443/cctvInfo?apiKey=${encodeURIComponent(apiKey)}&type=${type}&cctvType=${encodeURIComponent(cctvType)}&minX=${encodeURIComponent(minX)}&maxX=${encodeURIComponent(maxX)}&minY=${encodeURIComponent(minY)}&maxY=${encodeURIComponent(maxY)}&getType=json`; + const r = await fetch(url); + if (!r.ok) throw new Error(`ITS API error ${r.status} (${type})`); + const data = await r.json() as any; + return (data?.response?.data || []).map((it: any) => ({ ...it, _src: type })); + }; try { - const r = await fetch(url); - if (!r.ok) { res.status(502).json({ error: `ITS API error ${r.status}` }); return; } - const data = await r.json() as any; - const items: any[] = data?.response?.data || []; + const results = await Promise.allSettled(types.map(fetchType)); + const ok = results.filter((x): x is PromiseFulfilledResult => x.status === 'fulfilled'); + if (!ok.length) { + const first = results[0] as PromiseRejectedResult; + res.status(502).json({ error: String(first?.reason?.message || first?.reason || 'ITS API failed') }); + return; + } + const seen = new Set(); + const items = ok.flatMap(x => x.value).filter(it => { + const k = String(it.cctvurl || `${it.cctvname}|${it.coordx}|${it.coordy}`); + if (seen.has(k)) return false; + seen.add(k); + return true; + }); res.json({ count: items.length, items }); } catch (e: any) { res.status(502).json({ error: String(e?.message || e) }); diff --git a/web-ui/html/traffic-app.html b/web-ui/html/traffic-app.html index 616552e..8b4ba81 100644 --- a/web-ui/html/traffic-app.html +++ b/web-ui/html/traffic-app.html @@ -132,7 +132,7 @@ body{background:var(--bg);color:var(--text);font-family:system-ui,sans-serif;dis
- +