Files
takeyourmeds/public/lib/api.js
T
Frank Schwenk 1cada42370 feat: replace Web Push with ntfy for medication reminders
Single notification path via ntfy HTTP publish for reliable Android delivery;
remove VAPID, push subscriptions, and SW push handlers. PWA settings show
topic subscribe link; humor texts and deep-link actions unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 10:42:58 +02:00

32 lines
1.2 KiB
JavaScript

import { getToken, clearToken } from "./auth.js";
async function request(path, options = {}) {
const headers = { "Content-Type": "application/json", ...(options.headers || {}) };
const token = getToken();
if (token) headers.Authorization = `Bearer ${token}`;
const resp = await fetch(path, { ...options, headers });
if (resp.status === 401) {
clearToken();
window.location.reload();
throw new Error("Unauthorized");
}
if (!resp.ok) {
const err = await resp.json().catch(() => ({}));
throw new Error(err.detail || resp.statusText);
}
return resp.json();
}
export const api = {
login: (pin) => request("/api/auth/pin", { method: "POST", body: JSON.stringify({ pin }) }),
config: () => request("/api/config"),
today: () => request("/api/today"),
log: (data) => request("/api/log", { method: "POST", body: JSON.stringify(data) }),
history: (days = 90) => request(`/api/history?days=${days}`),
stats: () => request("/api/stats"),
roast: () => request("/api/roast"),
snooze: (slot_id, minutes) => request("/api/snooze", { method: "POST", body: JSON.stringify({ slot_id, minutes }) }),
notifyConfig: () => request("/api/notify-config"),
};