init
This commit is contained in:
commit
6250d23297
53 changed files with 6381 additions and 0 deletions
26
lib/weather/providers/openweather/index.ts
Normal file
26
lib/weather/providers/openweather/index.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { readKey } from "../../http";
|
||||
import type { WeatherProvider } from "../../types";
|
||||
import { getFreeForecast } from "./free";
|
||||
import { getOneCallForecast } from "./onecall";
|
||||
|
||||
/**
|
||||
* OpenWeather (the default provider).
|
||||
*
|
||||
* Set OPENWEATHER_PLAN in .env.local:
|
||||
* free (default) → 5 days in 3-hour steps
|
||||
* onecall → One Call 4.0: 48 hours hourly + daily, plus dew point and UV
|
||||
*/
|
||||
const usesOneCall = () => process.env.OPENWEATHER_PLAN === "onecall";
|
||||
|
||||
export const openWeather: WeatherProvider = {
|
||||
id: "openweather",
|
||||
label: "OpenWeather",
|
||||
envKey: "OPENWEATHER_API_KEY",
|
||||
signupUrl: "https://home.openweathermap.org/users/sign_up",
|
||||
limits: () => (usesOneCall() ? { forecastDays: 8, hourlyStepHours: 1 } : { forecastDays: 5, hourlyStepHours: 3 }),
|
||||
|
||||
getForecast(lat, lon) {
|
||||
const key = readKey("OPENWEATHER_API_KEY");
|
||||
return usesOneCall() ? getOneCallForecast(lat, lon, key) : getFreeForecast(lat, lon, key);
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue