fix: keep daily brief independent from warning checks

This commit is contained in:
zv
2026-06-12 21:43:34 +02:00
parent 763de7fd05
commit 1ff76cf847
3 changed files with 24 additions and 7 deletions

View File

@@ -2,14 +2,18 @@ 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";
const USER_AGENT = "wtr./1.0 (weather notification worker)";
export async function fetchMeteoWarnings(signal?: AbortSignal): Promise<WeatherWarning[]> {
const response = await fetch(IMGW_WARNINGS_METEO_URL, {
headers: { accept: "application/json" },
headers: { accept: "application/json", "user-agent": USER_AGENT },
next: { revalidate: 300 },
signal,
});
if (!response.ok) throw new Error("Unable to load IMGW meteorological warnings.");
if (!response.ok) {
const details = await response.text().catch(() => "");
throw new Error(`Unable to load IMGW meteorological warnings: ${response.status}${details ? ` ${details.slice(0, 240)}` : ""}`);
}
const rows = await response.json() as RawWarning[];
return Array.isArray(rows) ? rows.map((warning, index) => normalizeWarning(warning, "meteo", index)) : [];
}