From 41ab4564dc02e18433da70a08cf9def0ca717bcb Mon Sep 17 00:00:00 2001 From: kisfenyo Date: Thu, 26 Feb 2026 09:12:26 +0100 Subject: [PATCH] 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 --- app/tandoor.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/tandoor.py b/app/tandoor.py index 116694b..40d4570 100644 --- a/app/tandoor.py +++ b/app/tandoor.py @@ -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,