diff --git a/server.py b/server.py index 431709d..148acc3 100644 --- a/server.py +++ b/server.py @@ -6,6 +6,14 @@ from fastapi import FastAPI, File, Form, HTTPException, UploadFile from fastapi.staticfiles import StaticFiles from PIL import Image as PILImage +# Optional HEIC/HEIF support for iPhone photos +try: + from pillow_heif import register_heif_opener + register_heif_opener() + HAS_HEIF = True +except ImportError: + HAS_HEIF = False + try: import pytesseract HAS_TESSERACT = True @@ -148,7 +156,7 @@ async def analyze_photo(file: UploadFile = File(...)): file_size = len(contents) ext = Path(file.filename or "photo.jpg").suffix.lower() - if ext not in {".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff", ".tif", ".dng"}: + if ext not in {".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff", ".tif", ".dng", ".heic", ".heif"}: ext = ".jpg" fname = f"{uuid.uuid4().hex}{ext}" (UPLOADS / fname).write_bytes(contents) @@ -194,7 +202,7 @@ async def bulk_process(files: list[UploadFile] = File(...)): # Save ext = Path(file.filename or "photo.jpg").suffix.lower() - if ext not in {".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff", ".tif", ".dng"}: + if ext not in {".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff", ".tif", ".dng", ".heic", ".heif"}: ext = ".jpg" fname = f"{uuid.uuid4().hex}{ext}" (UPLOADS / fname).write_bytes(contents) diff --git a/static/index.html b/static/index.html index fc64673..f3b925c 100644 --- a/static/index.html +++ b/static/index.html @@ -304,9 +304,9 @@ document.getElementById('fileInput').addEventListener('change', async function(e '' ).join(''); - // Scan all in parallel (limited to 4 at a time to avoid memory issues) + // Scan in small batches — iOS Safari can't handle many concurrent file reads const results = []; - const batchSize = 4; + const batchSize = 2; for (let i = 0; i < files.length; i += batchSize) { const batch = files.slice(i, i + batchSize); const batchResults = await Promise.all(batch.map(f => scanPhoto(f))); @@ -321,12 +321,9 @@ document.getElementById('fileInput').addEventListener('change', async function(e async function scanPhoto(file) { const result = { file, exif: null, hasGps: false, lat: null, lng: null, thumb: null }; - // Generate thumbnail - result.thumb = await new Promise(resolve => { - const reader = new FileReader(); - reader.onload = e => resolve(e.target.result); - reader.readAsDataURL(file); - }); + // Use object URL instead of readAsDataURL — avoids loading the entire file + // into memory as a base64 string (the main cause of iOS hangs with many photos) + result.thumb = URL.createObjectURL(file); // Read EXIF try { @@ -726,6 +723,12 @@ async function pushGpsToAsset(idx) { } function resetAll() { + // Revoke all blob URLs to prevent memory leaks + allPhotos.forEach(p => { + if (p.thumb && p.thumb.startsWith('blob:')) { + URL.revokeObjectURL(p.thumb); + } + }); allPhotos = []; selectedIdx = -1; currentFilter = 'all'; diff --git a/uploads/0ed9143a7e684ffab74661520089a0da.jpg b/uploads/0ed9143a7e684ffab74661520089a0da.jpg new file mode 100644 index 0000000..f9afd87 Binary files /dev/null and b/uploads/0ed9143a7e684ffab74661520089a0da.jpg differ diff --git a/uploads/5b8b9a6e72bf4db6b1693d684214628a.jpg b/uploads/5b8b9a6e72bf4db6b1693d684214628a.jpg new file mode 100644 index 0000000..c6518db Binary files /dev/null and b/uploads/5b8b9a6e72bf4db6b1693d684214628a.jpg differ diff --git a/uploads/73d57c99c1cb4df4a7ccb9b49587bbb0.jpg b/uploads/73d57c99c1cb4df4a7ccb9b49587bbb0.jpg new file mode 100644 index 0000000..3bde230 Binary files /dev/null and b/uploads/73d57c99c1cb4df4a7ccb9b49587bbb0.jpg differ diff --git a/uploads/866a657a83824fe19314566af0bd634a.jpg b/uploads/866a657a83824fe19314566af0bd634a.jpg new file mode 100644 index 0000000..88a2d96 Binary files /dev/null and b/uploads/866a657a83824fe19314566af0bd634a.jpg differ diff --git a/uploads/b5e428e13b8840a7bf0e3c8fd219a1af.jpg b/uploads/b5e428e13b8840a7bf0e3c8fd219a1af.jpg new file mode 100644 index 0000000..5e74243 Binary files /dev/null and b/uploads/b5e428e13b8840a7bf0e3c8fd219a1af.jpg differ diff --git a/uploads/e43c484d08b144bfb34abc6826689f2f.jpg b/uploads/e43c484d08b144bfb34abc6826689f2f.jpg new file mode 100644 index 0000000..aa742b2 Binary files /dev/null and b/uploads/e43c484d08b144bfb34abc6826689f2f.jpg differ diff --git a/uploads/f10213b35c874c4fa61befae5730cef9.jpg b/uploads/f10213b35c874c4fa61befae5730cef9.jpg new file mode 100644 index 0000000..cb1fc4e Binary files /dev/null and b/uploads/f10213b35c874c4fa61befae5730cef9.jpg differ