Add Web Push warning notification backend

This commit is contained in:
zv
2026-06-11 19:17:13 +02:00
parent 531e678922
commit 054d75b1f4
15 changed files with 645 additions and 36 deletions

15
lib/server-warnings.ts Normal file
View File

@@ -0,0 +1,15 @@
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)) : [];
}