From 769f875faa19a48bb0e4118afbed0adaad3b893a Mon Sep 17 00:00:00 2001 From: otivm Date: Mon, 27 Apr 2026 10:41:11 +0000 Subject: [PATCH] Add fetchMapCells to api.js for TESSERA map endpoint --- src/api.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/api.js b/src/api.js index 5736643..43ee499 100644 --- a/src/api.js +++ b/src/api.js @@ -1,8 +1,10 @@ -// Thin client for the OTIVM save API +// Thin client for the OTIVM save and map APIs // Backend: GET /api/save/:token — load state // POST /api/save/:token — write state +// GET /api/map/:h5/:epoch — H7 land/sea cells for one waypoint at one epoch -const BASE = '/api/save' +const BASE_SAVE = '/api/save' +const BASE_MAP = '/api/map' // Generate a random 8-character hex token export function generateToken() { @@ -14,7 +16,7 @@ export function generateToken() { // Load state from server — returns parsed state object or null export async function loadState(token) { try { - const res = await fetch(`${BASE}/${token}`) + const res = await fetch(`${BASE_SAVE}/${token}`) if (!res.ok) return null return await res.json() } catch { @@ -25,7 +27,7 @@ export async function loadState(token) { // Save state to server — returns true on success export async function saveState(token, state) { try { - const res = await fetch(`${BASE}/${token}`, { + const res = await fetch(`${BASE_SAVE}/${token}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(state), @@ -35,3 +37,18 @@ export async function saveState(token, state) { return false } } + +// Fetch H7 land/sea classification for one H5 waypoint at one named epoch. +// h5: H3 res-5 hex string (e.g. '851e805bfffffff') +// epochKey: named epoch from paleo_epochs (e.g. 'roman_14bce') +// Returns: { epoch_key, sl_offset_cm, h5, cells: [{ h7, h7_land, h9_total, is_land }] } +// Returns null on any error. +export async function fetchMapCells(h5, epochKey) { + try { + const res = await fetch(`${BASE_MAP}/${h5}/${epochKey}`) + if (!res.ok) return null + return await res.json() + } catch { + return null + } +}