Skip to content

Commit

Permalink
Allow for image MINE types in API logo's
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Oct 2, 2024
1 parent 075de77 commit b34f660
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions server/api/collaboration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import re
import uuid
from datetime import datetime, timedelta, timezone

Expand Down Expand Up @@ -621,8 +622,9 @@ def save_collaboration_api():
logo = data.get("logo")
if logo:
try:
if "data:image/png;base64," in logo:
logo = logo[len("data:image/png;base64,"):]
groups = re.search(r"data:image/.*;base64,((.|\n)*)", logo)
if groups:
logo = groups[1]
decoded_bytes = base64.decodebytes(logo.encode())
data["logo"] = transform_image(decoded_bytes)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion server/test/api/test_collaboration.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def test_api_call_with_logo_prefix(self):
"disable_join_requests": True,
"disclose_member_information": True,
"disclose_email_information": True,
"logo": "data:image/png;base64," + read_image("robot.png"),
"logo": "data:image/WHATEVER;base64," + read_image("robot.png"),
"tags": ["label_1", "label_2", "1234567890123456789012345678901234"],
"units": ["Research", "Support"]
}),
Expand Down

0 comments on commit b34f660

Please sign in to comment.