Daily forecast fix?
This commit is contained in:
@@ -83,23 +83,26 @@ app.get('/api/hourly', async (req, res) => {
|
||||
// ── Hourly History/Forecast ───────────────────────────────────────────────────
|
||||
|
||||
app.get('/api/daily', async (req, res) => {
|
||||
const {fields} = req.query;
|
||||
const start = new Date(req.query.start) || new Date(new Date().setHours(0, 0, 0, 0));
|
||||
let now = new Date();
|
||||
now.setHours(0, 0, 0, 0);
|
||||
let next = new Date(now);
|
||||
next.setDate(now.getDate() + 1);
|
||||
const end = new Date(req.query.end) || new Date();
|
||||
const coords = await getCoords();
|
||||
const { fields } = req.query
|
||||
const now = new Date()
|
||||
now.setHours(0, 0, 0, 0)
|
||||
const next = new Date(now)
|
||||
next.setDate(now.getDate() + 1)
|
||||
const start = req.query.start ? new Date(req.query.start) : now
|
||||
const end = req.query.end ? new Date(req.query.end) : next
|
||||
const meteoStart = start >= next ? start : next
|
||||
const coords = await getCoords()
|
||||
|
||||
const [sensor, meteo] = await Promise.allSettled([
|
||||
now > start ? queryDaily(start.toISOString(), now.toISOString()) : Promise.resolve([]),
|
||||
getOpenMeteo(coords.latitude, coords.longitude, (start.getTime() > next.getTime() ? start : next).toISOString(), end.toISOString()),
|
||||
]);
|
||||
const history = sensor.status === 'fulfilled' ? sensor.value : [];
|
||||
const forecast = meteo.status === 'fulfilled' ? meteo.value.daily : [];
|
||||
const daily = getCelestialForecast(coords.latitude, coords.longitude, [...history, ...forecast]);
|
||||
res.json(filterArr(daily, fields));
|
||||
});
|
||||
start < now ? queryDaily(start.toISOString(), now.toISOString()) : Promise.resolve([]),
|
||||
end > now ? getOpenMeteo(coords.latitude, coords.longitude, meteoStart, end) : Promise.resolve([]),
|
||||
])
|
||||
|
||||
const history = sensor.status === 'fulfilled' ? sensor.value : []
|
||||
const forecast = meteo.status === 'fulfilled' ? meteo.value : []
|
||||
const daily = getCelestialForecast(coords.latitude, coords.longitude, [...history, ...forecast])
|
||||
res.json(filterArr(daily, fields))
|
||||
})
|
||||
|
||||
// ── ADSB Proxy ────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user