mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-08 06:38:46 +00:00
allow weather apis to use hidden api keys
This commit is contained in:
parent
08afa0b747
commit
5a8defb478
6 changed files with 61 additions and 12 deletions
|
@ -1,9 +1,28 @@
|
|||
import cachedFetch from "utils/cached-fetch";
|
||||
import { getSettings } from "utils/config";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { lat, lon, apiKey, duration } = req.query;
|
||||
const { latitude, longitude, provider, cache } = req.query;
|
||||
let { apiKey } = req.query;
|
||||
|
||||
const api_url = `http://api.weatherapi.com/v1/current.json?q=${lat},${lon}&key=${apiKey}`;
|
||||
if (!apiKey && !provider) {
|
||||
return res.status(400).json({ error: "Missing API key or provider" });
|
||||
}
|
||||
|
||||
res.send(await cachedFetch(api_url, duration));
|
||||
if (!apiKey && provider !== "weatherapi") {
|
||||
return res.status(400).json({ error: "Invalid provider for endpoint" });
|
||||
}
|
||||
|
||||
if (!apiKey && provider) {
|
||||
const settings = await getSettings();
|
||||
apiKey = settings?.providers?.weatherapi;
|
||||
}
|
||||
|
||||
if (!apiKey) {
|
||||
return res.status(400).json({ error: "Missing API key" });
|
||||
}
|
||||
|
||||
const api_url = `http://api.weatherapi.com/v1/current.json?q=${latitude},${longitude}&key=${apiKey}`;
|
||||
|
||||
res.send(await cachedFetch(api_url, cache));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue