Fix Tandoor image URLs: rewrite internal API URLs to public base URL
Images returned by Tandoor API use the internal service URL when api_url differs from base_url. Now rewritten to public URL so browser can display them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+10
-2
@@ -36,6 +36,14 @@ class TandoorClient:
|
||||
"Accept": "application/json",
|
||||
})
|
||||
|
||||
def _public_image_url(self, url: str) -> str:
|
||||
"""Rewrite an internal API image URL to the public base URL."""
|
||||
if not url:
|
||||
return ""
|
||||
if self.api_url != self.base_url and url.startswith(self.api_url):
|
||||
return self.base_url + url[len(self.api_url):]
|
||||
return url
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Public
|
||||
# ------------------------------------------------------------------
|
||||
@@ -104,7 +112,7 @@ class TandoorClient:
|
||||
items.append({
|
||||
"id": item["id"],
|
||||
"name": item.get("name", ""),
|
||||
"image": item.get("image") or "",
|
||||
"image": self._public_image_url(item.get("image") or ""),
|
||||
"tags": [k.get("name", "") for k in item.get("keywords", []) if k.get("name")],
|
||||
"url": f"{self.base_url}/view/recipe/{item['id']}",
|
||||
})
|
||||
@@ -161,7 +169,7 @@ class TandoorClient:
|
||||
return {
|
||||
"title": data.get("name", ""),
|
||||
"description": data.get("description", ""),
|
||||
"image_url": data.get("image") or "",
|
||||
"image_url": self._public_image_url(data.get("image") or ""),
|
||||
"ingredients": ingredients,
|
||||
"instructions": instructions,
|
||||
"tags": tags,
|
||||
|
||||
Reference in New Issue
Block a user