@@ -60,7 +60,9 @@ async def download_file(
60
60
ContentScannerRestError: The file was not found or could not be downloaded due
61
61
to an error on the remote homeserver's side.
62
62
"""
63
- url = await self ._build_https_url (media_path )
63
+ url = await self ._build_https_url (
64
+ media_path , for_thumbnail = thumbnail_params is not None
65
+ )
64
66
65
67
# Attempt to retrieve the file at the generated URL.
66
68
try :
@@ -71,7 +73,11 @@ async def download_file(
71
73
# again with an r0 endpoint.
72
74
logger .info ("File not found, trying legacy r0 path" )
73
75
74
- url = await self ._build_https_url (media_path , endpoint_version = "r0" )
76
+ url = await self ._build_https_url (
77
+ media_path ,
78
+ endpoint_version = "r0" ,
79
+ for_thumbnail = thumbnail_params is not None ,
80
+ )
75
81
76
82
try :
77
83
file = await self ._get_file_content (url , thumbnail_params )
@@ -89,6 +95,8 @@ async def _build_https_url(
89
95
self ,
90
96
media_path : str ,
91
97
endpoint_version : str = "v3" ,
98
+ * ,
99
+ for_thumbnail : bool ,
92
100
) -> str :
93
101
"""Turn a `server_name/media_id` path into an https:// one we can use to fetch
94
102
the media.
@@ -100,6 +108,9 @@ async def _build_https_url(
100
108
media_path: The media path to translate.
101
109
endpoint_version: The version of the download endpoint to use. As of Matrix
102
110
v1.1, this is either "v3" or "r0".
111
+ for_thumbnail: True if a server-side thumbnail is desired instead of the full
112
+ media. In that case, the URL for the `/thumbnail` endpoint is returned
113
+ instead of the `/download` endpoint.
103
114
104
115
Returns:
105
116
An https URL to use. If `base_homeserver_url` is set in the config, this
@@ -129,7 +140,9 @@ async def _build_https_url(
129
140
# didn't find a .well-known file.
130
141
base_url = "https://" + server_name
131
142
132
- prefix = self .MEDIA_DOWNLOAD_PREFIX
143
+ prefix = (
144
+ self .MEDIA_THUMBNAIL_PREFIX if for_thumbnail else self .MEDIA_DOWNLOAD_PREFIX
145
+ )
133
146
134
147
# Build the full URL.
135
148
path_prefix = prefix % endpoint_version
0 commit comments