feat(backend): products and categories point at the media library (platform-v2 step 5.2)
- products.media_id / categories.media_id (Alembic 0027): the old
/static/product_images photos are processed into the library (named after
their product; missing or unreadable files logged and skipped; the old
folder is left on disk) and products.image_url goes. The static mount is gone.
- APIs give `image` {id, name, thumb, card, full}; a product's image_url is its
card size. media_id on create/update (null clears); media.not_a_picture for
a video. POST /api/products/{id}/image is gone: uploads go to /api/media.
- Products and categories register their media usage: a photo in use can't
be deleted.
- Media: AVIF pictures (Pillow 12.3), GET /api/media/{id} gives each stored
size's bytes and resolution and the uploader's name; upload processing moved
into services/media.ingest (also used by the data move).
- QR menu photo push (contract C-3): the library's card size, WebP.
- tests: test_product_photos.py (7, incl. the 0027 data move); 497 passed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -204,28 +204,28 @@ async def _sync_once():
|
||||
# Online or not: the stored signed license decides (no more 72h offline rule)
|
||||
apply_license()
|
||||
|
||||
IMAGE_DIR = Path("/app/data/product_images")
|
||||
|
||||
|
||||
async def _push_product_images(db, products):
|
||||
"""Upload the local image file for each product whose picture changed since
|
||||
the last successful push (tracked via Product.cloud_image_hash), so the
|
||||
public QR menu can show it without needing a manually-set digital_image_url.
|
||||
Skips products that already have a manual digital_image_url override."""
|
||||
"""Upload each product's photo (the library's card size, WebP) whose file changed since the
|
||||
last successful push (Product.cloud_image_hash), so the public QR menu can show it without a
|
||||
manually-set digital_image_url. Skips products with a manual digital_image_url override."""
|
||||
import hashlib
|
||||
from services import media as media_store
|
||||
|
||||
site_numeric_id = license_state.get("site_numeric_id")
|
||||
if not site_numeric_id:
|
||||
return
|
||||
|
||||
for p in products:
|
||||
if p.digital_image_url or not p.image_url:
|
||||
if p.digital_image_url or p.media is None or p.media.kind != "image":
|
||||
continue
|
||||
|
||||
filename = os.path.basename(p.image_url)
|
||||
filepath = IMAGE_DIR / filename
|
||||
if not filepath.exists():
|
||||
try:
|
||||
path = media_store.ensure_variant(p.media, "card")
|
||||
except Exception:
|
||||
path = None
|
||||
if not path:
|
||||
continue
|
||||
filepath = Path(path)
|
||||
filename = f"{p.media.sha256[:16]}.webp"
|
||||
|
||||
try:
|
||||
contents = filepath.read_bytes()
|
||||
@@ -238,7 +238,7 @@ async def _push_product_images(db, products):
|
||||
f"{settings.CLOUD_URL}/api/menu/sync-image",
|
||||
headers={"X-Site-ID": settings.SITE_ID, "X-Site-Key": settings.SITE_KEY},
|
||||
data={"product_id": str(p.id)},
|
||||
files={"file": (filename, contents)},
|
||||
files={"file": (filename, contents, "image/webp")},
|
||||
)
|
||||
resp.raise_for_status()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user