Yuyao Huang f3bffa40cd Initial commit: GoalsBreakDown web app
- Flask backend with TinyDB database
- Multi-user auth with bcrypt password hashing
- Goal CRUD with activation/deactivation and per-user limits
- Task CRUD with status tracking (todo/doing/pending/done)
- Focus rule: one doing task per goal
- Time picker-style scroll view with drag-and-drop reordering
- Admin panel for user management
- uv environment management
2026-05-08 12:41:19 +08:00

46 lines
1.0 KiB
JavaScript

const API_BASE = "";
async function apiRequest(endpoint, options = {}) {
const url = API_BASE + endpoint;
const config = {
headers: {
"Content-Type": "application/json",
},
credentials: "same-origin",
...options,
};
if (options.body && typeof options.body === "object") {
config.body = JSON.stringify(options.body);
}
const response = await fetch(url, config);
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || "Request failed");
}
return data;
}
async function get(endpoint) {
return apiRequest(endpoint, { method: "GET" });
}
async function post(endpoint, body) {
return apiRequest(endpoint, { method: "POST", body });
}
async function put(endpoint, body) {
return apiRequest(endpoint, { method: "PUT", body });
}
async function del(endpoint) {
return apiRequest(endpoint, { method: "DELETE" });
}
async function patch(endpoint, body) {
return apiRequest(endpoint, { method: "PATCH", body });
}