|
|
@@ -307,42 +307,15 @@ async def catalog_images(
|
|
|
) -> dict[str, Any]:
|
|
|
"""
|
|
|
Return product images for a given model number.
|
|
|
- Fetches the image base URL from public.config and joins with shop picture tables.
|
|
|
+ Delegates to chatbot_api.catalog_images which reads File_Url from public.config
|
|
|
+ and joins shop.shop_product_picture with catalog.
|
|
|
Returns: { base_url, images: [{ model, apppicture_path, full_url }] }
|
|
|
"""
|
|
|
- assert DB_POOL is not None
|
|
|
-
|
|
|
- # Get image server base URL from config
|
|
|
- base_url_row = await DB_POOL.fetchrow(
|
|
|
- "SELECT item_value FROM public.config WHERE item = 'File_Url' LIMIT 1"
|
|
|
+ result = await call_single(
|
|
|
+ "SELECT chatbot_api.catalog_images($1, $2)",
|
|
|
+ req.model, req.limit,
|
|
|
)
|
|
|
- base_url: str = (base_url_row["item_value"] if base_url_row else "https://www.homelegance.com/").rstrip("/")
|
|
|
-
|
|
|
- # Fetch image paths for the requested model
|
|
|
- rows = await DB_POOL.fetch(
|
|
|
- """
|
|
|
- SELECT c.model, spp.apppicture_path
|
|
|
- FROM shop.shop_product_picture spp
|
|
|
- JOIN shop.shop_product sp ON spp.product_id = sp.product_id
|
|
|
- JOIN public.catalog c ON sp.caf_serial_no = c.serial_no
|
|
|
- WHERE c.model ILIKE $1
|
|
|
- LIMIT $2
|
|
|
- """,
|
|
|
- f"%{req.model}%",
|
|
|
- req.limit,
|
|
|
- )
|
|
|
-
|
|
|
- images = [
|
|
|
- {
|
|
|
- "model": row["model"],
|
|
|
- "apppicture_path": row["apppicture_path"],
|
|
|
- "full_url": f"{base_url}{row['apppicture_path']}",
|
|
|
- }
|
|
|
- for row in rows
|
|
|
- if row["apppicture_path"]
|
|
|
- ]
|
|
|
-
|
|
|
- return {"base_url": base_url, "images": images}
|
|
|
+ return result or {"base_url": "", "images": []}
|
|
|
|
|
|
|
|
|
# ──────────────────────────────────────────────────────────────────────────────
|