First commit, phased 1 and 2 created but untested

This commit is contained in:
bepis
2026-10-20 07:40:35 +11:00
commit 7a3e408ffc
66 changed files with 5639 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
const API_BASE = '/api';
const api = {
async post(path, body) {
const res = await fetch(`${API_BASE}${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify(body),
});
const data = await res.json();
if (!res.ok) {
const msg = data.error ? data.error.message : 'Request failed.';
const errorEl = document.getElementById('error');
if (errorEl) {
errorEl.textContent = msg;
errorEl.style.display = 'block';
}
throw new Error(msg);
}
return data.data;
},
async get(path) {
const res = await fetch(`${API_BASE}${path}`, {
credentials: 'include',
});
const data = await res.json();
if (!res.ok) {
const msg = data.error ? data.error.message : 'Request failed.';
const errorEl = document.getElementById('error');
if (errorEl) {
errorEl.textContent = msg;
errorEl.style.display = 'block';
}
throw new Error(msg);
}
return data.data;
},
};
function showError(msg) {
const errorEl = document.getElementById('error');
if (errorEl) {
errorEl.textContent = msg;
errorEl.style.display = 'block';
}
}