mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
28 lines
824 B
JavaScript
28 lines
824 B
JavaScript
import { fetchRegionalJson } from './http.js';
|
|
import { normalizeRegionalWeather } from '../../../src/data/regionalModel.js';
|
|
|
|
const WEATHER_EFFECTS_MAX_RESPONSE_BYTES = 512 * 1024;
|
|
|
|
async function fetchRegionalWeather(point) {
|
|
const params = new URLSearchParams({
|
|
latitude: point.latitude.toFixed(5),
|
|
longitude: point.longitude.toFixed(5),
|
|
current:
|
|
'temperature_2m,apparent_temperature,precipitation,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m,visibility',
|
|
timezone: 'UTC',
|
|
});
|
|
try {
|
|
const payload = await fetchRegionalJson(
|
|
`https://api.open-meteo.com/v1/forecast?${params}`,
|
|
{
|
|
maxBytes: WEATHER_EFFECTS_MAX_RESPONSE_BYTES,
|
|
},
|
|
);
|
|
return normalizeRegionalWeather(payload);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export { fetchRegionalWeather };
|