Add Web Push warning notification backend
This commit is contained in:
15
lib/server-warnings.ts
Normal file
15
lib/server-warnings.ts
Normal 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)) : [];
|
||||
}
|
||||
Reference in New Issue
Block a user