Files
wtr/lib/server-warnings.ts

16 lines
704 B
TypeScript

import { normalizeWarning } from "@/lib/weather-utils";
import type { RawWarning, WeatherWarning } from "@/types/imgw";
const IMGW_WARNINGS_METEO_URL = "https://danepubliczne.imgw.pl/api/data/warningsmeteo";
export async function fetchMeteoWarnings(signal?: AbortSignal): Promise<WeatherWarning[]> {
const response = await fetch(IMGW_WARNINGS_METEO_URL, {
headers: { accept: "application/json" },
next: { revalidate: 300 },
signal,
});
if (!response.ok) throw new Error("Unable to load IMGW meteorological warnings.");
const rows = await response.json() as RawWarning[];
return Array.isArray(rows) ? rows.map((warning, index) => normalizeWarning(warning, "meteo", index)) : [];
}