summary refs log tree commit diff
path: root/synapse/rest/media/v1/thumbnail_resource.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-06-23 11:14:11 +0100
committerErik Johnston <erik@matrix.org>2017-06-23 11:14:11 +0100
commit7fe8ed1787ca0c1f7a4c56aa1c85e486b76f4550 (patch)
treea2bd30b908118a6e9dff04259e7e2b54d6d6b44a /synapse/rest/media/v1/thumbnail_resource.py
parentMerge pull request #2297 from matrix-org/erikj/user_dir_fix (diff)
downloadsynapse-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/thumbnail_resource.py')
-rw-r--r--synapse/rest/media/v1/thumbnail_resource.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/synapse/rest/media/v1/thumbnail_resource.py b/synapse/rest/media/v1/thumbnail_resource.py
index 59b2c39b2f..68d56b2b10 100644
--- a/synapse/rest/media/v1/thumbnail_resource.py
+++ b/synapse/rest/media/v1/thumbnail_resource.py
@@ -101,9 +101,16 @@ class ThumbnailResource(Resource):
             t_type = thumbnail_info["thumbnail_type"]
             t_method = thumbnail_info["thumbnail_method"]
 
-            file_path = self.filepaths.local_media_thumbnail(
-                media_id, t_width, t_height, t_type, t_method,
-            )
+            if media_info["url_cache"]:
+                # TODO: Check the file still exists, if it doesn't we can redownload
+                # it from the url `media_info["url_cache"]`
+                file_path = self.filepaths.url_cache_thumbnail(
+                    media_id, t_width, t_height, t_type, t_method,
+                )
+            else:
+                file_path = self.filepaths.local_media_thumbnail(
+                    media_id, t_width, t_height, t_type, t_method,
+                )
             yield respond_with_file(request, t_type, file_path)
 
         else:
@@ -134,9 +141,18 @@ class ThumbnailResource(Resource):
             t_type = info["thumbnail_type"] == desired_type
 
             if t_w and t_h and t_method and t_type:
-                file_path = self.filepaths.local_media_thumbnail(
-                    media_id, desired_width, desired_height, desired_type, desired_method,
-                )
+                if media_info["url_cache"]:
+                    # TODO: Check the file still exists, if it doesn't we can redownload
+                    # it from the url `media_info["url_cache"]`
+                    file_path = self.filepaths.url_cache_thumbnail(
+                        media_id, desired_width, desired_height, desired_type,
+                        desired_method,
+                    )
+                else:
+                    file_path = self.filepaths.local_media_thumbnail(
+                        media_id, desired_width, desired_height, desired_type,
+                        desired_method,
+                    )
                 yield respond_with_file(request, desired_type, file_path)
                 return