HEIC thumbnails: pull full file (partial reads unreliable for sips conversion)

1MB partial HEIC reads are not sufficient for sips to convert to JPEG.
Revert to full file pull for HEIC thumbnails. Files are cached permanently
so each HEIC is only transferred once — subsequent launches skip already-cached files.
This commit is contained in:
Kyle Bolen
2026-07-30 03:57:44 +00:00
parent 30b600e2a4
commit 558a7add89
2 changed files with 17 additions and 22 deletions

View File

@@ -176,15 +176,20 @@ async def cmd_batch_thumbs(pairs_json: str):
for device_path, local_path in pairs:
ext = device_path.rsplit('.', 1)[-1].lower() if '.' in device_path else ''
is_heic = ext in ('heic', 'heif')
read_size = 1024 * 1024 if is_heic else 512 * 1024 # 1MB for HEIC, 512KB for others
try:
os.makedirs(os.path.dirname(os.path.abspath(local_path)), exist_ok=True)
try:
data = await afc.fread(device_path, read_size, 0)
with open(local_path, 'wb') as f:
f.write(data)
except Exception:
if is_heic:
# HEIC: pull full file — sips needs the full image to convert to JPEG
# Cached permanently so only transferred once
await afc.pull(device_path, local_path)
else:
# JPEG/PNG: 512KB partial read is sufficient for sips resample
try:
data = await afc.fread(device_path, 512 * 1024, 0)
with open(local_path, 'wb') as f:
f.write(data)
except Exception:
await afc.pull(device_path, local_path)
results.append({'devicePath': device_path, 'ok': True})
except Exception as e:
results.append({'devicePath': device_path, 'ok': False, 'error': str(e)})