DNG/RAW photo support for gallery upload

- Server: accept .dng in OCR endpoint (PIL opens as TIFF)
- Server: bump OCR size limit to 20MB (DNG files can be large)
- Client: gallery upload tries server OCR first (with 6s timeout),
  then falls back to client-side Tesseract.js — matches 📸 capture flow
- DNG photos now work with 'Pick from Gallery'
This commit is contained in:
2026-05-21 14:51:57 -04:00
parent 97699a95ea
commit 0cf5dddf83
2 changed files with 25 additions and 4 deletions
+22 -1
View File
@@ -2638,7 +2638,28 @@
if (ocrEl) ocrEl.textContent = '⏳ Running OCR...';
try {
const ocrData = await ocrImageClient(file);
// Try server OCR first (handles more formats like DNG/RAW)
let ocrData = null;
try {
const controller = new AbortController();
const t = setTimeout(() => controller.abort(), 6000);
const fd = new FormData();
fd.append('file', file, file.name || 'sticker.jpg');
const res = await fetch('/api/ocr', {
method: 'POST', body: fd, signal: controller.signal,
headers: AppState.authToken
? { 'Authorization': 'Bearer ' + AppState.authToken } : {},
});
clearTimeout(t);
if (res.ok) {
ocrData = await res.json();
}
} catch (_) { /* server OCR failed, fall through to client */ }
if (!ocrData || !ocrData.machine_id) {
// Fall back to client-side Tesseract.js
ocrData = await ocrImageClient(file);
}
if (ocrData && ocrData.machine_id) {
document.getElementById('scanMachineId').value = ocrData.machine_id;
if (ocrEl) ocrEl.innerHTML = `✅ Machine ID: <strong>${esc(ocrData.machine_id)}</strong>` +