feat: add global weather support
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m54s

This commit is contained in:
zv
2026-06-14 15:53:34 +02:00
parent d572c9cc53
commit 2182297adc
45 changed files with 739 additions and 212 deletions

View File

@@ -1,5 +1,6 @@
import { toNumber } from "@/lib/weather-utils";
import type { ImgwCurrentWeather, RawImgwHybridWeatherResponse, RawImgwHybridWeatherRow } from "@/types/imgw-current";
import type { WeatherRegion } from "@/types/weather-region";
const STALE_TEN_MINUTE_THRESHOLD_MS = 2 * 60 * 60 * 1000;
@@ -104,6 +105,12 @@ export function normalizeImgwCurrentWeather(payload: RawImgwHybridWeatherRespons
return {
coverage: fullRow?.row.Type === "Type_Ten_Minutes" ? "full" : fullRow ? "hourly" : "precipitation-only",
region: "PL",
source: "IMGW",
sourceLabel: "IMGW Hybrid",
sourceType: fullRow ? "hybrid" : "model",
isOfficial: true,
fetchedAt: new Date().toISOString(),
measuredAt: row.measuredAt,
temperature: toCelsius(row.row.Temperature),
feelsLike: toCelsius(row.row.Chill),
@@ -126,3 +133,10 @@ export async function fetchImgwCurrentWeather(latitude: number, longitude: numbe
if (!response.ok) throw new Error("Nie udało się pobrać bieżącej analizy IMGW Hybrid.");
return normalizeImgwCurrentWeather(await response.json() as RawImgwHybridWeatherResponse);
}
export async function fetchCurrentWeather(latitude: number, longitude: number, region: WeatherRegion, signal?: AbortSignal) {
const params = new URLSearchParams({ latitude: String(latitude), longitude: String(longitude), region });
const response = await fetch(`/api/current-weather?${params}`, { signal });
if (!response.ok) throw new Error("Nie udało się pobrać bieżących warunków pogodowych.");
return await response.json() as ImgwCurrentWeather | null;
}