feat(ingest): localize inline post-body images to local copies (Phase 2)
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:
@@ -35,6 +35,7 @@ from ..utils import safe_probe
|
||||
from ..utils.paths import (
|
||||
derive_subdir,
|
||||
derive_top_level_artist,
|
||||
filehash_from_url,
|
||||
hash_suffixed_name,
|
||||
safe_ext,
|
||||
)
|
||||
@@ -1046,6 +1047,14 @@ class Importer:
|
||||
if record.artist_id is None:
|
||||
record.artist_id = artist.id
|
||||
|
||||
# #830 Phase 2: persist the file's CDN source identity (NULL-only, so a
|
||||
# re-import / enrich-on-duplicate never clobbers it) — the filehash is
|
||||
# the join key that lets post_feed_service remap the body's inline
|
||||
# `<img src=CDN>` to this local copy at render time.
|
||||
if sd.source_url and record.source_filehash is None:
|
||||
record.source_url = sd.source_url
|
||||
record.source_filehash = filehash_from_url(sd.source_url)
|
||||
|
||||
if explicit_source is not None:
|
||||
src = explicit_source
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user