From d55cc4aa443763ff9199fee2bce8f396b21d8de5 Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 21 May 2026 14:09:14 -0400 Subject: [PATCH] gallery upload: GPS fallback + auto-lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GPS: when EXIF stripped by mobile browser, falls back to navigator.geolocation.getCurrentPosition() for device location - OCR result now populates scanMachineId hidden field so Create works - createFromScanPhoto also checks AppState.gpsLat as fallback - Gallery OCR now auto-lookups via handleBarcode() — routes to confirm card (existing asset) or new asset form (not found) - Manual entry button also calls handleBarcode() after prompt --- static/index.html | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/static/index.html b/static/index.html index 5fe3371..53a6399 100644 --- a/static/index.html +++ b/static/index.html @@ -2621,16 +2621,19 @@ try { const ocrData = await ocrImageClient(file); if (ocrData && ocrData.machine_id) { + document.getElementById('scanMachineId').value = ocrData.machine_id; if (ocrEl) ocrEl.innerHTML = `✅ Machine ID: ${esc(ocrData.machine_id)}` + (ocrData.confidence === 'low' ? ' ⚠️ Low confidence' : ''); + // Auto-lookup like barcode scan — route to confirm card or new asset form + handleBarcode(ocrData.machine_id); } else { - if (ocrEl) ocrEl.innerHTML = '❌ No machine ID detected. '; + if (ocrEl) ocrEl.innerHTML = '❌ No machine ID detected. '; } } catch (ocrErr) { if (ocrEl) ocrEl.textContent = '❌ OCR failed: ' + ocrErr.message; } - // Extract GPS from EXIF + // Extract GPS from EXIF — fall back to device GPS if stripped const gpsEl = document.getElementById('scanGpsResult'); try { const gps = await extractGpsFromPhoto(file); @@ -2638,13 +2641,34 @@ pickedPhotoGps = gps; if (gpsEl) { gpsEl.style.display = 'block'; - gpsEl.innerHTML = `📍 GPS: ${gps.lat.toFixed(6)}, ${gps.lng.toFixed(6)}`; + gpsEl.innerHTML = `📍 GPS: ${gps.lat.toFixed(6)}, ${gps.lng.toFixed(6)} (from photo)`; } } else { + // EXIF GPS stripped by browser — try device GPS if (gpsEl) { + gpsEl.innerHTML = '📍 No GPS in photo — trying device location...'; gpsEl.style.display = 'block'; - gpsEl.innerHTML = '📍 No GPS data in photo'; } + navigator.geolocation.getCurrentPosition( + pos => { + const lat = pos.coords.latitude; + const lng = pos.coords.longitude; + const acc = pos.coords.accuracy; + pickedPhotoGps = { lat, lng, accuracy: acc }; + AppState.gpsLat = lat; + AppState.gpsLng = lng; + AppState.gpsAcc = acc; + if (gpsEl) { + gpsEl.innerHTML = `📍 GPS: ${lat.toFixed(6)}, ${lng.toFixed(6)} (from device)`; + } + }, + err => { + if (gpsEl) { + gpsEl.innerHTML = `📍 No GPS — ${err.message}. Enter manually after creating.`; + } + }, + { enableHighAccuracy: true, timeout: 10000 } + ); } } catch (gpsErr) { if (gpsEl) { @@ -2667,6 +2691,9 @@ if (pickedPhotoGps) { payload.latitude = pickedPhotoGps.lat; payload.longitude = pickedPhotoGps.lng; + } else if (AppState.gpsLat) { + payload.latitude = AppState.gpsLat; + payload.longitude = AppState.gpsLng; } api('/api/connect-label', {