Files
electronics-inventory/public/lib/api.mjs
mikael-lovqvists-claude-agent cf37759893 Add grid image system with multi-panel support and SPA routing
- Grid images: photograph component boxes in sub-sections, assemble
  into one logical grid via perspective warp (homography)
- Source image gallery: bulk upload photos separately from grid setup
- Grid drafts: persist partial work, resume across sessions
- Multi-panel grids: define rows/cols per photo, system computes panel
  layout; process partially configured grids, edit individual panels
- Pan/zoom canvas editor (HiDPI-aware, touch support) for corner alignment
- SPA routing with canonical URLs (history.pushState, server catch-all)
- Express error visibility: uncaughtException/unhandledRejection handlers
  and 4-arg error middleware
- Original filename stored on source image upload
- Various null-safety fixes and CSS [hidden] override fixes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-20 23:30:17 +00:00

46 lines
2.1 KiB
JavaScript

async function req(method, path, body) {
const opts = { method, headers: {} };
if (body !== undefined) {
opts.headers['Content-Type'] = 'application/json';
opts.body = JSON.stringify(body);
}
const res = await fetch(path, opts);
const data = await res.json();
if (!data.ok) throw new Error(data.error ?? 'Request failed');
return data;
}
// Fields
export const get_fields = () => req('GET', '/api/fields');
export const create_field = (body) => req('POST', '/api/fields', body);
export const update_field = (id, body) => req('PUT', `/api/fields/${id}`, body);
export const delete_field = (id) => req('DELETE', `/api/fields/${id}`);
// Components
export const get_components = () => req('GET', '/api/components');
export const create_component = (body) => req('POST', '/api/components', body);
export const update_component = (id, body) => req('PUT', `/api/components/${id}`, body);
export const delete_component = (id) => req('DELETE', `/api/components/${id}`);
// Inventory
export const get_inventory = () => req('GET', '/api/inventory');
export const create_inventory = (body) => req('POST', '/api/inventory', body);
export const update_inventory = (id, body) => req('PUT', `/api/inventory/${id}`, body);
export const delete_inventory = (id) => req('DELETE', `/api/inventory/${id}`);
// Grid drafts
export const get_grid_drafts = () => req('GET', '/api/grid-drafts');
export const create_grid_draft = (body) => req('POST', '/api/grid-drafts', body);
export const update_grid_draft = (id, body) => req('PUT', `/api/grid-drafts/${id}`, body);
export const delete_grid_draft = (id) => req('DELETE', `/api/grid-drafts/${id}`);
// Source images
export const get_source_images = () => req('GET', '/api/source-images');
export const delete_source_image = (id) => req('DELETE', `/api/source-images/${id}`);
// Grid images
export const get_grids = () => req('GET', '/api/grid-images');
export const get_grid = (id) => req('GET', `/api/grid-images/${id}`);
export const delete_grid = (id) => req('DELETE', `/api/grid-images/${id}`);
export const update_grid_panel = (id, pi, body) => req('PUT', `/api/grid-images/${id}/panels/${pi}`, body);