Class: Helios::Press::ImageIngestor
- Inherits:
-
Object
- Object
- Helios::Press::ImageIngestor
- Defined in:
- app/services/helios/press/image_ingestor.rb
Overview
Downloads remote images referenced in ingested post HTML, stores them via ActiveStorage, and rewrites the body HTML so <img> src attributes point at locally-hosted ActiveStorage proxy URLs.
Supports two modes:
1. Explicit references: src="helios://image/<reference_key>" paired with
an images_payload array containing download URLs.
2. Auto-import: any remaining src="https://..." URLs are downloaded,
deduplicated by a SHA256 of the URL path.
Defined Under Namespace
Classes: FetchError
Constant Summary collapse
- MAX_BYTES =
15.megabytes
Instance Method Summary collapse
-
#call(body_html:, images_payload: []) ⇒ Object
images_payload: Array of Hashes [{ “reference_key” => “abc123”, “url” => “https://…”, “alt” => “…”, “caption” => “…” }].
-
#initialize(post) ⇒ ImageIngestor
constructor
A new instance of ImageIngestor.
Constructor Details
#initialize(post) ⇒ ImageIngestor
Returns a new instance of ImageIngestor.
24 25 26 |
# File 'app/services/helios/press/image_ingestor.rb', line 24 def initialize(post) @post = post end |
Instance Method Details
#call(body_html:, images_payload: []) ⇒ Object
images_payload: Array of Hashes
[{ "reference_key" => "abc123", "url" => "https://...", "alt" => "...", "caption" => "..." }]
30 31 32 33 34 35 36 37 |
# File 'app/services/helios/press/image_ingestor.rb', line 30 def call(body_html:, images_payload: []) ensure_text_block! upsert_inline_images(images_payload) rewritten = rewrite_body_html(body_html) text_block.content = rewritten text_block.save! rewritten end |