fix(photos): 入库压缩保留 EXIF 并补未来上传的压缩缺口

- 迁移器与新增 photos_ingest.py 压缩时显式 exif= 传参(PIL 重存默认
  剥离——此前 21 张已全部丢 EXIF,图库参数条构建期数据源被抽空)
- exif=None 会使 PIL JPEG 保存 len(None) 崩,改条件传参
- photos_ingest.py:幂等入库处理器(长边 2400/q86,>1.5M 才动),
  堵住 gitea/本地上传原图直入仓的缺口(196M 事故成因)
- 重跑迁移:19/21 带 EXIF(2 张原图本无),体积 9.7M

验证: pnpm astro build 11 页 exit 0;EXIF 保留计数 19/21

Spec: none (Phase 2 归档后的独立小修:EXIF 修复 + ingest 补缺)

Co-authored-by: GLM-5.3
This commit is contained in:
wait4xandGLM-5.3 committed 2026-10-25 09:01:07 +08:00
1 parent aea21c8694
commit 382e56431f
21 files changed
+52 -1

No files matched your search

+5 -1
View File
@@ -32,11 +32,15 @@ def compress(data: bytes) -> bytes:
from PIL import Image
img = Image.open(BytesIO(data))
# EXIF 必须显式带上:PIL 重存默认剥离,而构建期 exifr 正是从文件提 EXIF
exif = img.info.get("exif")
if img.mode not in ("RGB", "L"):
img = img.convert("RGB")
img.thumbnail((2400, 2400))
buf = BytesIO()
img.save(buf, "JPEG", quality=86, optimize=True)
# PIL 的 JPEG 保存不接受 exif=None(len(None) 崩),仅在确有 EXIF 时传参
kwargs = {"exif": exif} if exif else {}
img.save(buf, "JPEG", quality=86, optimize=True, **kwargs)
return buf.getvalue()