Initial commit
Photo-based book cataloger with AI identification. Room → Cabinet → Shelf → Book hierarchy; FastAPI + SQLite backend; vanilla JS SPA; OpenAI-compatible plugin system for boundary detection, text recognition, and archive search.
This commit is contained in:
23
static/js/api.js
Normal file
23
static/js/api.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* api.js
|
||||
* Single fetch wrapper used for all server communication.
|
||||
* Throws an Error with the server's detail message on non-2xx responses.
|
||||
*
|
||||
* Provides: req(method, url, body?, isForm?)
|
||||
* Depends on: nothing
|
||||
*/
|
||||
|
||||
// ── API ──────────────────────────────────────────────────────────────────────
|
||||
async function req(method, url, body = null, isForm = false) {
|
||||
const opts = {method};
|
||||
if (body) {
|
||||
if (isForm) { opts.body = body; }
|
||||
else { opts.headers = {'Content-Type':'application/json'}; opts.body = JSON.stringify(body); }
|
||||
}
|
||||
const r = await fetch(url, opts);
|
||||
if (!r.ok) {
|
||||
const e = await r.json().catch(() => ({detail:'Request failed'}));
|
||||
throw new Error(e.detail || 'Request failed');
|
||||
}
|
||||
return r.json();
|
||||
}
|
||||
Reference in New Issue
Block a user