Brand image display cards

This commit is contained in:
sriram
2026-09-02 13:34:40 +05:30
parent 5399fea4cc
commit d5ec5755bf
8 changed files with 921 additions and 18 deletions

View File

@@ -14,6 +14,7 @@ from app.api.schemas import (
ProductListOut,
ProductOut,
)
from app.services.brand_registry import get_brand_logo
from app.services.s3_service import s3_service
from app.services.vector_store import (
get_brand_overview,
@@ -142,9 +143,22 @@ def get_brand_cards(
cards = []
for row in rows:
name = row["display_name"]
image_url = _clean_url(row.get("sample_image_url"))
# A curated logo wins over a sampled product photo. It has to be first,
# not a fallback: the brands that need one do not have an EMPTY
# sample_image_url, they have a non-empty string that only fails when
# the browser tries to fetch it. Ordering this second would leave them
# exactly as broken as they are now.
image_url = _clean_url(get_brand_logo(name)) or _clean_url(row.get("sample_image_url"))
if not image_url and s3_service.enabled and row.get("sample_image_id"):
image_url = s3_service.get_product_image_url(name, row["sample_image_id"])
# LIST, don't construct. get_product_image_url() builds
# .../{image_id}/image_000.jpg and returns it whether or not the
# object exists, which is how four brands ended up serving URLs
# that 404 on every request. get_product_image_urls() does a real
# list_objects_v2, so an empty result means genuinely no image -
# and it finds .jpeg where the constructor assumed .jpg.
listed = s3_service.get_product_image_urls(name, row["sample_image_id"])
image_url = _clean_url(listed[0]) if listed else None
cards.append(BrandCardOut(
name=name,