Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 0c763bf

Browse files
committed
Assume required properties exist.
1 parent 0501d08 commit 0c763bf

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

synapse/rest/media/v1/oembed.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ def parse_oembed_response(self, url: str, body: str) -> OEmbedResult:
107107
result = json_decoder.decode(body)
108108

109109
# Ensure there's a version of 1.0.
110-
if result.get("version") != "1.0":
111-
raise RuntimeError("Invalid version: %s" % (result.get("version"),))
112-
113-
oembed_type = result.get("type")
110+
oembed_version = result["version"]
111+
if oembed_version != "1.0":
112+
raise RuntimeError(f"Invalid version: {oembed_version}")
114113

115114
# Ensure the cache age is None or an int.
116115
cache_age = result.get("cache_age")
@@ -125,12 +124,13 @@ def parse_oembed_response(self, url: str, body: str) -> OEmbedResult:
125124
og["og:image"] = result["thumbnail_url"]
126125

127126
# Process each type separately.
127+
oembed_type = result["type"]
128128
if oembed_type == "rich":
129-
calc_description_and_urls(og, result.get("html"))
129+
calc_description_and_urls(og, result["html"])
130130

131131
elif oembed_type == "photo":
132132
# If this is a photo, use the full image, not the thumbnail.
133-
og["og:image"] = result.get("url")
133+
og["og:image"] = result["url"]
134134

135135
else:
136136
raise RuntimeError(f"Unknown oEmbed type: {oembed_type}")

0 commit comments

Comments
 (0)