simpleshop_theme/lib/mix/tasks/simpleshop/download_images.ex
jamey 1b49b470f2 feat: add product image download pipeline for PageSpeed 100%
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>
2026-02-01 00:26:19 +00:00

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