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:
@@ -101,6 +101,25 @@ def test_sidecar_creates_provenance(importer, import_layout):
|
||||
assert rec.effective_date == post.post_date
|
||||
|
||||
|
||||
def test_sidecar_source_url_persists_filehash(importer, import_layout):
|
||||
"""#830 Phase 2: a media sidecar's source_url lands on the ImageRecord as
|
||||
source_url + the lowercased CDN filehash (the inline-image join key)."""
|
||||
import_root, _ = import_layout
|
||||
m = import_root / "Alice" / "b.jpg"
|
||||
_split(m, "v")
|
||||
_sidecar(m, {
|
||||
"category": "patreon", "id": 901, "title": "Body post",
|
||||
"source_url": "https://cdn.test/p/0123456789ABCDEF0123456789abcdef/b.jpg",
|
||||
})
|
||||
r = importer.import_one(m)
|
||||
assert r.status == "imported"
|
||||
rec = importer.session.get(ImageRecord, r.image_id)
|
||||
assert rec.source_url == (
|
||||
"https://cdn.test/p/0123456789ABCDEF0123456789abcdef/b.jpg"
|
||||
)
|
||||
assert rec.source_filehash == "0123456789abcdef0123456789abcdef"
|
||||
|
||||
|
||||
def test_reimport_same_post_idempotent(importer, import_layout):
|
||||
import_root, _ = import_layout
|
||||
# Threshold 0: only an exact phash match collapses. Orthogonal splits
|
||||
|
||||
Reference in New Issue
Block a user