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:
@@ -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")
|
||||
|
||||
+22
-1
@@ -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>` +
|
||||
|
||||
Reference in New Issue
Block a user