Skip to content

Commit

Permalink
fix: use image.openfoodfacts.* as default server for serving images
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Jan 10, 2023
1 parent 5178bac commit 70aceee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion robotoff/off.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ def generate_json_path(barcode: str, image_id: str) -> str:


def generate_json_ocr_url(barcode: str, image_id: str) -> str:
return settings.BaseURLProvider.image_url(generate_json_path(barcode, image_id))
return (
settings.BaseURLProvider.static()
+ f"/images/products{generate_json_path(barcode, image_id)}"
)


def generate_image_url(barcode: str, image_id: str) -> str:
Expand Down
10 changes: 9 additions & 1 deletion robotoff/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ def static() -> str:

@staticmethod
def image_url(image_path: str) -> str:
return BaseURLProvider.static() + f"/images/products{image_path}"
# If STATIC_OFF_DOMAIN is defined, used the custom static domain
# configured
# Otherwise use images.openfoodfacts.{net,org} as proxy server
prefix = (
BaseURLProvider.static()
if os.environ.get("STATIC_OFF_DOMAIN")
else BaseURLProvider._get_url(prefix="images")
)
return prefix + f"/images/products{image_path}"

@staticmethod
def country(country_code: str) -> str:
Expand Down

0 comments on commit 70aceee

Please sign in to comment.