diff options
author | Erik Johnston <erik@matrix.org> | 2017-06-23 11:14:11 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-06-23 11:14:11 +0100 |
commit | 7fe8ed1787ca0c1f7a4c56aa1c85e486b76f4550 (patch) | |
tree | a2bd30b908118a6e9dff04259e7e2b54d6d6b44a /synapse/rest/media/v1/media_repository.py | |
parent | Merge pull request #2297 from matrix-org/erikj/user_dir_fix (diff) | |
download | synapse-7fe8ed1787ca0c1f7a4c56aa1c85e486b76f4550.tar.xz |
Store URL cache preview downloads seperately
This makes it easier to clear old media out at a later date
Diffstat (limited to 'synapse/rest/media/v1/media_repository.py')
-rw-r--r-- | synapse/rest/media/v1/media_repository.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/synapse/rest/media/v1/media_repository.py b/synapse/rest/media/v1/media_repository.py index 0718f75241..0ea1248ce6 100644 --- a/synapse/rest/media/v1/media_repository.py +++ b/synapse/rest/media/v1/media_repository.py @@ -326,13 +326,17 @@ class MediaRepository(object): defer.returnValue(t_path) @defer.inlineCallbacks - def _generate_local_thumbnails(self, media_id, media_info): + def _generate_local_thumbnails(self, media_id, media_info, url_cache=False): media_type = media_info["media_type"] requirements = self._get_thumbnail_requirements(media_type) if not requirements: return - input_path = self.filepaths.local_media_filepath(media_id) + if url_cache: + input_path = self.filepaths.url_cache_filepath(media_id) + else: + input_path = self.filepaths.local_media_filepath(media_id) + thumbnailer = Thumbnailer(input_path) m_width = thumbnailer.width m_height = thumbnailer.height @@ -360,9 +364,14 @@ class MediaRepository(object): for t_width, t_height, t_type in scales: t_method = "scale" - t_path = self.filepaths.local_media_thumbnail( - media_id, t_width, t_height, t_type, t_method - ) + if url_cache: + t_path = self.filepaths.url_cache_thumbnail( + media_id, t_width, t_height, t_type, t_method + ) + else: + t_path = self.filepaths.local_media_thumbnail( + media_id, t_width, t_height, t_type, t_method + ) self._makedirs(t_path) t_len = thumbnailer.scale(t_path, t_width, t_height, t_type) @@ -377,9 +386,14 @@ class MediaRepository(object): # thumbnail. continue t_method = "crop" - t_path = self.filepaths.local_media_thumbnail( - media_id, t_width, t_height, t_type, t_method - ) + if url_cache: + t_path = self.filepaths.url_cache_thumbnail( + media_id, t_width, t_height, t_type, t_method + ) + else: + t_path = self.filepaths.local_media_thumbnail( + media_id, t_width, t_height, t_type, t_method + ) self._makedirs(t_path) t_len = thumbnailer.crop(t_path, t_width, t_height, t_type) local_thumbnails.append(( |