summary refs log tree commit diff
path: root/synapse/util/templates.py
diff options
context:
space:
mode:
authorPatrick Cloke <patrickc@matrix.org>2021-02-11 11:30:16 -0500
committerPatrick Cloke <patrickc@matrix.org>2021-02-11 11:30:16 -0500
commitfa0f99e4f2ff3fdedf03f700b2c11004166f991f (patch)
tree8ae535542771484573b944785ec132b80b2a9cd5 /synapse/util/templates.py
parentRevert "block groups requests to fosdem" (diff)
parentClarify when new ratelimiting was added. (diff)
downloadsynapse-fa0f99e4f2ff3fdedf03f700b2c11004166f991f.tar.xz
Merge branch 'release-v1.27.0' into matrix-org-hotfixes
Diffstat (limited to 'synapse/util/templates.py')
-rw-r--r--synapse/util/templates.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/synapse/util/templates.py b/synapse/util/templates.py

index 7e5109d206..392dae4a40 100644 --- a/synapse/util/templates.py +++ b/synapse/util/templates.py
@@ -17,7 +17,7 @@ import time import urllib.parse -from typing import TYPE_CHECKING, Callable, Iterable, Union +from typing import TYPE_CHECKING, Callable, Iterable, Optional, Union import jinja2 @@ -74,14 +74,23 @@ def build_jinja_env( return env -def _create_mxc_to_http_filter(public_baseurl: str) -> Callable: +def _create_mxc_to_http_filter( + public_baseurl: Optional[str], +) -> Callable[[str, int, int, str], str]: """Create and return a jinja2 filter that converts MXC urls to HTTP Args: public_baseurl: The public, accessible base URL of the homeserver """ - def mxc_to_http_filter(value, width, height, resize_method="crop"): + def mxc_to_http_filter( + value: str, width: int, height: int, resize_method: str = "crop" + ) -> str: + if not public_baseurl: + raise RuntimeError( + "public_baseurl must be set in the homeserver config to convert MXC URLs to HTTP URLs." + ) + if value[0:6] != "mxc://": return ""