Placeholder wind/rain measurements

This commit is contained in:
2026-06-23 23:11:15 -04:00
parent 40ec87d356
commit a174864ddb
5 changed files with 140 additions and 113 deletions

View File

@@ -2,15 +2,18 @@ export const BASE = import.meta.env.DEV ? 'http://10.69.5.23' : ''
export type DataRow = Record<string, number | string | null>
const cache: any = {};
async function get<T>(path: string, params: Record<string, string> = {}): Promise<T> {
const url = new URL(`${BASE}${path}`, window.location.origin)
Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v))
const res = await fetch(url.toString())
return res.json()
if(cache[url.toString()]) return cache[url.toString()];
cache[url.toString()] = await fetch(url.toString()).then(resp => resp.json()).finally(() => { delete cache[url.toString()]; });
return cache[url.toString()]
}
export const api = {
current: (fields?: string) => get<DataRow>('/api/data', fields ? { fields } : {}),
current: (fields?: string) => get<DataRow>('/api/current', fields ? { fields } : {}),
hourly: (start?: string, end?: string, fields?: string) => get<DataRow[]>('/api/hourly', { ...(start ? { start } : {}), ...(end ? { end } : {}), ...(fields ? { fields } : {}) }),
daily: (start?: string, end?: string, fields?: string) => get<DataRow[]>('/api/daily', { ...(start ? { start } : {}), ...(end ? { end } : {}), ...(fields ? { fields } : {}) }),
}