Skip to content

Commit

Permalink
FIX: Link in the author approval throws error 500 if the article cont…
Browse files Browse the repository at this point in the history
…ains images [TGA-83]
  • Loading branch information
devketanpro committed Feb 27, 2024
1 parent f41cbca commit 410f8b6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/tga/sign_off/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ def get_css_filename():

def modify_asset_urls(item, author_id: ObjectId):
pattern = re.compile('\/api\/upload-raw\/(.*?)"')
new_body_html = item["body_html"]
new_body_html = item.get("body_html", "")
url_prefix = "/api/upload-raw/"
url_prefix_len = len(url_prefix)

for asset_filename in re.findall(pattern, item["body_html"]):
for asset_filename in re.findall(pattern, item.get("body_html", "")):
asset_token = gen_jwt_for_approval_request(asset_filename, author_id, "upload-raw", token_expiration=3600)
new_body_html = new_body_html.replace(
url_prefix + asset_filename, f"/api/sign_off_requests/upload-raw/{asset_token}"
Expand All @@ -148,6 +148,11 @@ def modify_asset_urls(item, author_id: ObjectId):
continue
for size_name, rendition in (association.get("renditions") or {}).items():
rendition_href = rendition["href"]

if "s3.amazonaws.com" in rendition_href:
# Skip modification, if it is pointing to Amazon S3
continue

asset_filename = rendition_href[rendition_href.index(url_prefix) + url_prefix_len :]
asset_token = gen_jwt_for_approval_request(asset_filename, author_id, "upload-raw", token_expiration=3600)
rendition["href"] = rendition_href.replace(
Expand Down

0 comments on commit 410f8b6

Please sign in to comment.