diff --git a/server.py b/server.py index 05839b0..30ab1d8 100644 --- a/server.py +++ b/server.py @@ -2629,12 +2629,12 @@ async def ocr_sticker(file: UploadFile = File(...)): """ # Validate file extension ext = file.filename.rsplit(".", 1)[-1].lower() if "." in (file.filename or "") else "" - if ext not in {"png", "jpg", "jpeg", "webp", "bmp"}: + if ext not in {"png", "jpg", "jpeg", "webp", "bmp", "dng"}: raise HTTPException(status_code=400, detail=f"Unsupported image format: .{ext}") contents = await file.read() - if len(contents) > 10 * 1024 * 1024: # 10MB max - raise HTTPException(status_code=400, detail="Image too large (max 10MB)") + if len(contents) > 20 * 1024 * 1024: # 20MB max + raise HTTPException(status_code=400, detail="Image too large (max 20MB)") # Save temp file for OCR temp_dir = Path(UPLOADS_DIR / "ocr") diff --git a/static/index.html b/static/index.html index fa695af..31cce68 100644 --- a/static/index.html +++ b/static/index.html @@ -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: ${esc(ocrData.machine_id)}` +