Downloads Printify CDN images via ImageDownloadWorker, processes through Media pipeline (WebP conversion, AVIF/WebP variant generation), and links to ProductImage via new image_id FK. - Add image_id to product_images table - ImageDownloadWorker downloads and processes external images - sync_product_images preserves image_id when URL unchanged - PreviewData uses local images for responsive <picture> elements - VariantCache enqueues pending downloads on startup - mix simpleshop.download_images backfill task Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
42 lines
1.1 KiB
Elixir
42 lines
1.1 KiB
Elixir
defmodule Mix.Tasks.Simpleshop.DownloadImages do
|
|
@moduledoc """
|
|
Enqueues download jobs for product images that haven't been processed yet.
|
|
|
|
## Usage
|
|
|
|
mix simpleshop.download_images
|
|
|
|
This task finds all product images with a `src` URL but no linked `image_id`
|
|
and enqueues them for download via the ImageDownloadWorker.
|
|
|
|
Use this to backfill existing products after enabling the image download pipeline.
|
|
"""
|
|
|
|
use Mix.Task
|
|
|
|
@shortdoc "Enqueue product image downloads"
|
|
|
|
@impl Mix.Task
|
|
def run(_args) do
|
|
Mix.Task.run("app.start")
|
|
|
|
alias SimpleshopTheme.Products
|
|
alias SimpleshopTheme.Sync.ImageDownloadWorker
|
|
|
|
pending = Products.list_pending_downloads(limit: 10_000)
|
|
count = length(pending)
|
|
|
|
if count == 0 do
|
|
Mix.shell().info("No pending product images to download.")
|
|
else
|
|
Mix.shell().info("Enqueueing #{count} product images for download...")
|
|
|
|
Enum.each(pending, fn image ->
|
|
ImageDownloadWorker.enqueue(image.id)
|
|
end)
|
|
|
|
Mix.shell().info("Done. Images will be processed by Oban workers.")
|
|
end
|
|
end
|
|
end
|