feat(ingest): localize inline post-body images to local copies (Phase 2)
CI / lint (push) Successful in 2s
CI / frontend-build (push) Successful in 22s
CI / backend-lint-and-test (push) Successful in 38s
CI / integration (push) Successful in 3m14s

Render a post body faithfully by serving our stored copies of inline
images instead of hotlinking the public CDN. The join key is the CDN
filehash (32-hex MD5) shared between a body <img src> and the media URL
we downloaded (the same identity extract_media dedups by):

- utils.paths.filehash_from_url — one source of truth for the extractor;
  patreon_client._filehash now delegates so capture- and render-time
  hashing cannot drift.
- ImageRecord gains source_url (provenance) + source_filehash (indexed
  match key); migration 0051.
- the per-media sidecar carries the file's source_url; the importer
  persists it (NULL-only) on the ImageRecord via _apply_sidecar.
- post_feed_service.get_post remaps body <img src> -> /images/<path> for
  every inline image whose filehash maps to a stored image of THIS
  artist; unmatched / pre-Phase-2 images keep hotlinking.

Pre-existing on-disk images have no filehash yet, so they fall back to
hotlinking until re-downloaded; localization is forward-looking.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-14 16:39:58 -04:00
parent 5e1655384f
commit 96c29c370b
15 changed files with 350 additions and 22 deletions
+11
View File
@@ -27,6 +27,11 @@ class SidecarData:
description: str | None
attachment_count: int | None
post_date: datetime | None
# Per-FILE CDN/origin URL the media was downloaded from (#830 Phase 2). Only
# the per-media sidecar carries it; post-only sidecars leave it None. The
# importer persists it on the ImageRecord so the body's inline `<img src>`
# can be matched (by filehash) to the local copy at render time.
source_url: str | None
raw: dict
@@ -172,6 +177,11 @@ def parse_sidecar(data: dict) -> SidecarData:
else:
post_url = _first_str(data, ("url", "post_url"))
# Per-file source URL (#830 Phase 2): the native downloader writes it into
# each media sidecar. `url` is the post permalink for Patreon (handled
# above), so source_url has its own dedicated key and never collides.
source_url = _first_str(data, ("source_url",))
return SidecarData(
platform=platform,
external_post_id=external_post_id,
@@ -180,5 +190,6 @@ def parse_sidecar(data: dict) -> SidecarData:
description=description,
attachment_count=attachment_count,
post_date=post_date,
source_url=source_url,
raw=data,
)