diff options
Diffstat (limited to 'synapse/rest/media/v1/media_repository.py')
-rw-r--r-- | synapse/rest/media/v1/media_repository.py | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py index 4c9946a616..a0162d4255 100644 --- a/synapse/rest/media/v1/media_repository.py +++ b/synapse/rest/media/v1/media_repository.py @@ -184,7 +184,7 @@ class MediaRepository: async def get_local_media( self, request: Request, media_id: str, name: Optional[str] ) -> None: - """Responds to reqests for local media, if exists, or returns 404. + """Responds to requests for local media, if exists, or returns 404. Args: request: The incoming request. @@ -306,7 +306,7 @@ class MediaRepository: media_info = await self.store.get_cached_remote_media(server_name, media_id) # file_id is the ID we use to track the file locally. If we've already - # seen the file then reuse the existing ID, otherwise genereate a new + # seen the file then reuse the existing ID, otherwise generate a new # one. # If we have an entry in the DB, try and look for it @@ -325,7 +325,10 @@ class MediaRepository: # Failed to find the file anywhere, lets download it. try: - media_info = await self._download_remote_file(server_name, media_id,) + media_info = await self._download_remote_file( + server_name, + media_id, + ) except SynapseError: raise except Exception as e: @@ -351,7 +354,11 @@ class MediaRepository: responder = await self.media_storage.fetch_media(file_info) return responder, media_info - async def _download_remote_file(self, server_name: str, media_id: str,) -> dict: + async def _download_remote_file( + self, + server_name: str, + media_id: str, + ) -> dict: """Attempt to download the remote file from the given server name, using the given file_id as the local id. @@ -773,7 +780,11 @@ class MediaRepository: ) except Exception as e: thumbnail_exists = await self.store.get_remote_media_thumbnail( - server_name, media_id, t_width, t_height, t_type, + server_name, + media_id, + t_width, + t_height, + t_type, ) if not thumbnail_exists: raise e @@ -832,7 +843,10 @@ class MediaRepository: return await self._remove_local_media_from_disk([media_id]) async def delete_old_local_media( - self, before_ts: int, size_gt: int = 0, keep_profiles: bool = True, + self, + before_ts: int, + size_gt: int = 0, + keep_profiles: bool = True, ) -> Tuple[List[str], int]: """ Delete local or remote media from this server by size and timestamp. Removes @@ -849,7 +863,9 @@ class MediaRepository: A tuple of (list of deleted media IDs, total deleted media IDs). """ old_media = await self.store.get_local_media_before( - before_ts, size_gt, keep_profiles, + before_ts, + size_gt, + keep_profiles, ) return await self._remove_local_media_from_disk(old_media) @@ -927,10 +943,10 @@ class MediaRepositoryResource(Resource): <thumbnail> - The thumbnail methods are "crop" and "scale". "scale" trys to return an + The thumbnail methods are "crop" and "scale". "scale" tries to return an image where either the width or the height is smaller than the requested size. The client should then scale and letterbox the image if it needs to - fit within a given rectangle. "crop" trys to return an image where the + fit within a given rectangle. "crop" tries to return an image where the width and height are close to the requested size and the aspect matches the requested size. The client should scale the image if it needs to fit within a given rectangle. |