mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-01-14 09:09:42 -05:00
Make a config option for whether to generate new thumbnail sizes dynamically
This commit is contained in:
parent
459085184c
commit
7e3d1c7d92
@ -22,6 +22,7 @@ class ContentRepositoryConfig(Config):
|
|||||||
self.max_image_pixels = self.parse_size(config["max_image_pixels"])
|
self.max_image_pixels = self.parse_size(config["max_image_pixels"])
|
||||||
self.media_store_path = self.ensure_directory(config["media_store_path"])
|
self.media_store_path = self.ensure_directory(config["media_store_path"])
|
||||||
self.uploads_path = self.ensure_directory(config["uploads_path"])
|
self.uploads_path = self.ensure_directory(config["uploads_path"])
|
||||||
|
self.dynamic_thumbnails = config["dynamic_thumbnails"]
|
||||||
|
|
||||||
def default_config(self, config_dir_path, server_name):
|
def default_config(self, config_dir_path, server_name):
|
||||||
media_store = self.default_path("media_store")
|
media_store = self.default_path("media_store")
|
||||||
@ -38,4 +39,11 @@ class ContentRepositoryConfig(Config):
|
|||||||
|
|
||||||
# Maximum number of pixels that will be thumbnailed
|
# Maximum number of pixels that will be thumbnailed
|
||||||
max_image_pixels: "32M"
|
max_image_pixels: "32M"
|
||||||
|
|
||||||
|
# Whether to generate new thumbnails on the fly to precisely match
|
||||||
|
# the resolution requested by the client. If true then whenever
|
||||||
|
# a new resolution is requested by the client the server will
|
||||||
|
# generate a new thumbnail. If false the server will pick a thumbnail
|
||||||
|
# from a precalcualted list.
|
||||||
|
dynamic_thumbnails: false
|
||||||
""" % locals()
|
""" % locals()
|
||||||
|
@ -69,6 +69,7 @@ class BaseMediaResource(Resource):
|
|||||||
self.filepaths = filepaths
|
self.filepaths = filepaths
|
||||||
self.version_string = hs.version_string
|
self.version_string = hs.version_string
|
||||||
self.downloads = {}
|
self.downloads = {}
|
||||||
|
self.dynamic_thumbnails = hs.config.dynamic_thumbnails
|
||||||
|
|
||||||
def _respond_404(self, request):
|
def _respond_404(self, request):
|
||||||
respond_with_json(
|
respond_with_json(
|
||||||
|
@ -43,14 +43,25 @@ class ThumbnailResource(BaseMediaResource):
|
|||||||
m_type = parse_string(request, "type", "image/png")
|
m_type = parse_string(request, "type", "image/png")
|
||||||
|
|
||||||
if server_name == self.server_name:
|
if server_name == self.server_name:
|
||||||
yield self._select_or_generate_local_thumbnail(
|
if self.dynamic_thumbnails:
|
||||||
request, media_id, width, height, method, m_type
|
yield self._select_or_generate_local_thumbnail(
|
||||||
)
|
request, media_id, width, height, method, m_type
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
yield self._respond_local_thumbnail(
|
||||||
|
request, media_id, width, height, method, m_type
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
yield self._select_or_generate_remote_thumbnail(
|
if self.dynamic_thumbnails:
|
||||||
request, server_name, media_id,
|
yield self._select_or_generate_remote_thumbnail(
|
||||||
width, height, method, m_type
|
request, server_name, media_id,
|
||||||
)
|
width, height, method, m_type
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
yield self._respond_remote_thumbnail(
|
||||||
|
request, server_name, media_id,
|
||||||
|
width, height, method, m_type
|
||||||
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _respond_local_thumbnail(self, request, media_id, width, height,
|
def _respond_local_thumbnail(self, request, media_id, width, height,
|
||||||
|
Loading…
Reference in New Issue
Block a user