initial commit

This commit is contained in:
jhartworks
2026-06-22 13:29:30 +02:00
commit 9b651f1cd6
135 changed files with 66045 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
const API_URL = import.meta.env.VITE_API_URL || "http://localhost:18080/api";
async function request(path, options = {}) {
const response = await fetch(API_URL + path, {
headers: {
"Content-Type": "application/json",
...(options.token ? { Authorization: "Bearer " + options.token } : {}),
...options.headers,
},
method: options.method || "GET",
body: options.body ? JSON.stringify(options.body) : undefined,
});
if (response.status === 204) {
return null;
}
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || "Request failed.");
}
return data;
}
export const api = {
login: (body) => request("/auth/login", { method: "POST", body }),
me: (token) => request("/auth/me", { token }),
health: () => request("/health"),
getIsps: (token) => request("/isps", { token }),
getAliases: (token, isp) => request("/isps/" + isp + "/aliases", { token }),
saveAliases: (token, isp, body) =>
request("/isps/" + isp + "/aliases", { method: "PUT", token, body }),
importSql: (token, body) => request("/admin/import-sql", { method: "POST", token, body }),
getUsers: (token) => request("/users", { token }),
createUser: (token, body) => request("/users", { method: "POST", token, body }),
updateUser: (token, id, body) => request("/users/" + id, { method: "PATCH", token, body }),
getSelections: (token) => request("/selections", { token }),
createSelection: (token, body) => request("/selections", { method: "POST", token, body }),
updateSelection: (token, id, body) => request("/selections/" + id, { method: "PUT", token, body }),
deleteSelection: (token, id) => request("/selections/" + id, { method: "DELETE", token }),
queryTrends: (token, body) => request("/trends/query", { method: "POST", token, body }),
latestValues: (token, body) => request("/points/latest", { method: "POST", token, body }),
getDashboard: (token) => request("/dashboard", { token }),
saveDashboard: (token, body) => request("/dashboard", { method: "PUT", token, body }),
loadDashboardData: (token, body) => request("/dashboard/data", { method: "POST", token, body }),
getPreferences: (token) => request("/preferences", { token }),
savePreferences: (token, body) => request("/preferences", { method: "PUT", token, body }),
};