From 44bfb23efbd0bea97ae058c06c54b08d38ad73df Mon Sep 17 00:00:00 2001 From: wait4xx Date: Sun, 25 Oct 2026 09:12:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(gallery):=20=E5=8E=9F=E5=9B=BE=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E4=B8=8E=E4=B8=8B=E8=BD=BD=E2=80=94=E2=80=94=E4=BB=93?= =?UTF-8?q?=E5=A4=96=20originals=20store=20=E5=8F=8C=E8=BD=A8=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - git 仓只进压缩版(构建用);原图落 ~/docker_apps/blog/photos-originals/ (迁移器/ingest 双入口写入,幂等),build.sh 独立 rsync 到 staging/photos-originals/(同一静态根,零 nginx 改动) - lightbox 增「原图」(新标签全尺寸)+「下载」(download 属性带文件名) - 原图持久保障:store + Phase 0 备份 tar 双留档;存量 21 张已回填(196M) 验证: astro build 11 页 exit 0;dist/gallery 含 lb-original×2 与 photos-originals 引用;staging/photos-originals 21 张实测 Spec: none (用户功能补req:原图查看/下载,跨 Phase 独立小特性) Co-authored-by: GLM-5.3 --- infra/deploy/build.sh | 3 +++ scripts/migrate/photos_migrate.py | 8 ++++--- scripts/photos_ingest.py | 5 ++++ src/pages/gallery/index.astro | 38 ++++++++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/infra/deploy/build.sh b/infra/deploy/build.sh index 1499df7..669b063 100644 --- a/infra/deploy/build.sh +++ b/infra/deploy/build.sh @@ -13,5 +13,8 @@ pnpm astro build echo "[build] rsync -> $STAGING" mkdir -p "$STAGING" rsync -a --delete "$REPO_DIR/dist/" "$STAGING/" +# 原图仓独立同步(不进 git/dist):/photos-originals/ 供图库"查看原图/下载" +ORIG="$HOME/docker_apps/blog/photos-originals" +if [ -d "$ORIG" ]; then rsync -a "$ORIG/" "$STAGING/photos-originals/"; fi printf 'built at %s\n' "$(date -Is)" > "$STAGING/.build-stamp" echo "[build] done: $(find "$STAGING" -name '*.html' | wc -l) html files" diff --git a/scripts/migrate/photos_migrate.py b/scripts/migrate/photos_migrate.py index be3fad8..3e7d3b9 100644 --- a/scripts/migrate/photos_migrate.py +++ b/scripts/migrate/photos_migrate.py @@ -61,9 +61,11 @@ def main() -> int: fname = unquote(url.rsplit("/", 1)[1]) slug = slugify(spec.get("displayName") or fname) data = urllib.request.urlopen(BASE + url, timeout=60).read() - # 入仓前压到长边 2400/q86:原图总计 196M(单张最大 28M)会永久膨胀 - # 公开仓历史并撞死 nginx 100M 推送上限;原图已随 Phase 0 备份归档, - # 站内展示由 sharp 出 srcset,2400px 足够 lightbox 全屏 + # 原图双留档:仓外 originals store(构建时独立 rsync,服务"查看原图/ + # 下载")+ Phase 0 备份 tar;git 仓只进压缩版(196M 事故教训) + STORE = Path.home() / "docker_apps/blog/photos-originals" + STORE.mkdir(parents=True, exist_ok=True) + (STORE / f"{slug}.jpg").write_bytes(data) (OUT / f"{slug}.jpg").write_bytes(compress(data)) (OUT / f"{slug}.json").write_text(json.dumps({ diff --git a/scripts/photos_ingest.py b/scripts/photos_ingest.py index dd86e3f..36337ff 100644 --- a/scripts/photos_ingest.py +++ b/scripts/photos_ingest.py @@ -27,6 +27,11 @@ def main() -> int: if size < SKIP_BELOW_BYTES: skipped += 1 continue + STORE = Path.home() / "docker_apps/blog/photos-originals" + STORE.mkdir(parents=True, exist_ok=True) + # 压缩覆写仓内文件前原件先进 store(幂等:store 已有同名则跳过) + if not (STORE / jpg.name).exists(): + (STORE / jpg.name).write_bytes(jpg.read_bytes()) img = Image.open(jpg) # EXIF 显式保留:重存默认剥离会抽走图库参数条的构建期数据源 exif = img.info.get("exif") diff --git a/src/pages/gallery/index.astro b/src/pages/gallery/index.astro index 52cb16e..74ece9d 100644 --- a/src/pages/gallery/index.astro +++ b/src/pages/gallery/index.astro @@ -47,6 +47,8 @@ const cards = await Promise.all( image: photo.data.image, exif: formatExif(photo.data.exif), fullSrc: full.src, + // 原图走仓外 store(构建时独立 rsync 到 /photos-originals/),git 不背 196M + original: `/photos-originals/${photo.id}.jpg`, w, h, s3: spanFor(w, h, 3), @@ -84,6 +86,7 @@ const first = cards[0]; data-title={card.title} data-exif={card.exif} data-full={card.fullSrc} + data-original={card.original} aria-label={`查看大图:${card.title}${card.exif ? `(${card.exif})` : ''}`} > {first?.title} {first?.exif} + + 原图 + 下载 +