교통 CCTV: 고속도로(type=ex)도 함께 불러오기 — 국도(its)만 불러 인천이 5개뿐이던 문제(합치면 117개); 탭 이름 '고속도로·국도'

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-18 21:46:19 +09:00
1 parent 4c3c3ff2a4
commit a51d130b86
2 files changed
+26 -6

No files matched your search

+25 -5
View File
@@ -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<string, string>;
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<string, string>).type || 'all');
const types = want === 'its' ? ['its'] : want === 'ex' ? ['ex'] : ['its', 'ex'];
const fetchType = async (type: string): Promise<any[]> => {
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<any[]> => 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<string>();
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) });
+1 -1
View File
@@ -132,7 +132,7 @@ body{background:var(--bg);color:var(--text);font-family:system-ui,sans-serif;dis
<div style="display:flex;flex-direction:column;flex:1;min-height:0;">
<!-- 탭 바 -->
<div class="tab-bar">
<button class="tab-btn active" id="tab-its" onclick="switchTab('its')">📡 ITS 고속도로 CCTV</button>
<button class="tab-btn active" id="tab-its" onclick="switchTab('its')">📡 ITS 고속도로·국도 CCTV</button>
<button class="tab-btn" id="tab-utic" onclick="switchTab('utic')">🗺️ UTIC 교통지도</button>
</div>