mirror of https://github.com/zulip/zulip.git
thumbnails: Add setting THUMBNAIL_IMAGES.
This setting splits away part of responsibility from THUMBOR_URL. Now on, this setting will be responsible for controlling whether we thumbnail images or not by asking bugdown to render image links to hit our /thumbnail endpoint. This is irrespective of what THUMBOR_URL is set to though ideally THUMBOR_URL should be set to point to a running thumbor instance.
This commit is contained in:
parent
9e9bd2456f
commit
3ee69f3da9
|
@ -28,7 +28,7 @@ Thumbor is responsible for a few things in Zulip:
|
||||||
Thumbor handles a lot of details for us, varying from signing of
|
Thumbor handles a lot of details for us, varying from signing of
|
||||||
thumbnailing URLs, to caching for DoS prevention.
|
thumbnailing URLs, to caching for DoS prevention.
|
||||||
|
|
||||||
It is configured via the `THUMBOR_URL` setting in
|
It is configured via the `THUMBOR_URL` and `THUMBNAIL_IMAGES` settings in
|
||||||
`/etc/zulip/settings.py`; you can host Thumbor on the same machine as
|
`/etc/zulip/settings.py`; you can host Thumbor on the same machine as
|
||||||
the Zulip server, or a remote server (which is better for isolation,
|
the Zulip server, or a remote server (which is better for isolation,
|
||||||
since security bugs in image-processing libraries have in the past
|
since security bugs in image-processing libraries have in the past
|
||||||
|
|
|
@ -35,7 +35,7 @@ from zerver.lib.emoji import translate_emoticons, emoticon_regex
|
||||||
from zerver.lib.mention import possible_mentions, \
|
from zerver.lib.mention import possible_mentions, \
|
||||||
possible_user_group_mentions, extract_user_group
|
possible_user_group_mentions, extract_user_group
|
||||||
from zerver.lib.url_encoding import encode_stream
|
from zerver.lib.url_encoding import encode_stream
|
||||||
from zerver.lib.thumbnail import is_thumbor_enabled, user_uploads_or_external
|
from zerver.lib.thumbnail import user_uploads_or_external
|
||||||
from zerver.lib.timeout import timeout, TimeoutExpired
|
from zerver.lib.timeout import timeout, TimeoutExpired
|
||||||
from zerver.lib.cache import cache_with_key, NotFoundInCache
|
from zerver.lib.cache import cache_with_key, NotFoundInCache
|
||||||
from zerver.lib.url_preview import preview as link_preview
|
from zerver.lib.url_preview import preview as link_preview
|
||||||
|
@ -309,7 +309,7 @@ def add_a(
|
||||||
if data_id is not None:
|
if data_id is not None:
|
||||||
a.set("data-id", data_id)
|
a.set("data-id", data_id)
|
||||||
img = markdown.util.etree.SubElement(a, "img")
|
img = markdown.util.etree.SubElement(a, "img")
|
||||||
if is_thumbor_enabled() and (not already_thumbnailed) and user_uploads_or_external(url):
|
if settings.THUMBNAIL_IMAGES and (not already_thumbnailed) and user_uploads_or_external(url):
|
||||||
# See docs/thumbnailing.md for some high-level documentation.
|
# See docs/thumbnailing.md for some high-level documentation.
|
||||||
#
|
#
|
||||||
# We strip leading '/' from relative URLs here to ensure
|
# We strip leading '/' from relative URLs here to ensure
|
||||||
|
|
|
@ -379,7 +379,7 @@ class BugdownTest(ZulipTestCase):
|
||||||
|
|
||||||
msg = 'https://www.google.com/images/srpr/logo4w.png'
|
msg = 'https://www.google.com/images/srpr/logo4w.png'
|
||||||
thumbnail_img = '<div class="message_inline_image"><a href="https://www.google.com/images/srpr/logo4w.png" target="_blank" title="https://www.google.com/images/srpr/logo4w.png"><img src="https://www.google.com/images/srpr/logo4w.png"></a></div>'
|
thumbnail_img = '<div class="message_inline_image"><a href="https://www.google.com/images/srpr/logo4w.png" target="_blank" title="https://www.google.com/images/srpr/logo4w.png"><img src="https://www.google.com/images/srpr/logo4w.png"></a></div>'
|
||||||
with self.settings(THUMBOR_URL=''):
|
with self.settings(THUMBNAIL_IMAGES=False):
|
||||||
converted = bugdown_convert(msg)
|
converted = bugdown_convert(msg)
|
||||||
self.assertIn(thumbnail_img, converted)
|
self.assertIn(thumbnail_img, converted)
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ if FAKE_LDAP_MODE:
|
||||||
AUTHENTICATION_BACKENDS += ('zproject.backends.ZulipLDAPAuthBackend',) # type: ignore # tuple hackery
|
AUTHENTICATION_BACKENDS += ('zproject.backends.ZulipLDAPAuthBackend',) # type: ignore # tuple hackery
|
||||||
|
|
||||||
THUMBOR_URL = 'http://127.0.0.1:9995'
|
THUMBOR_URL = 'http://127.0.0.1:9995'
|
||||||
|
THUMBNAIL_IMAGES = True
|
||||||
|
|
||||||
SEARCH_PILLS_ENABLED = os.getenv('SEARCH_PILLS_ENABLED', False)
|
SEARCH_PILLS_ENABLED = os.getenv('SEARCH_PILLS_ENABLED', False)
|
||||||
|
|
||||||
|
|
|
@ -516,9 +516,14 @@ CAMO_URI = '/external_content/'
|
||||||
# By default, Zulip connects to the thumbor (the thumbnailing software
|
# By default, Zulip connects to the thumbor (the thumbnailing software
|
||||||
# we use) service running locally on the machine. If you're running
|
# we use) service running locally on the machine. If you're running
|
||||||
# thumbor on a different server, you can configure that by setting
|
# thumbor on a different server, you can configure that by setting
|
||||||
# THUMBOR_URL here. Setting THUMBOR_URL='' will disable
|
# THUMBOR_URL here. Setting THUMBOR_URL='' will let Zulip server know that
|
||||||
# thumbnailing in Zulip.
|
# thumbor is not running or configured.
|
||||||
#THUMBOR_URL = 'http://127.0.0.1:9995'
|
#THUMBOR_URL = 'http://127.0.0.1:9995'
|
||||||
|
#
|
||||||
|
# This setting controls whether images shown in Zulip's inline image
|
||||||
|
# previews should be thumbnailed by thumbor, which saves bandwidth but
|
||||||
|
# can modify the image's appearance.
|
||||||
|
#THUMBNAIL_IMAGES = True
|
||||||
|
|
||||||
# Controls the Jitsi video call integration. By default, the
|
# Controls the Jitsi video call integration. By default, the
|
||||||
# integration uses the SaaS meet.jit.si server. You can specify
|
# integration uses the SaaS meet.jit.si server. You can specify
|
||||||
|
|
|
@ -209,6 +209,7 @@ DEFAULT_SETTINGS = {
|
||||||
'REMOTE_POSTGRES_HOST': '',
|
'REMOTE_POSTGRES_HOST': '',
|
||||||
'REMOTE_POSTGRES_SSLMODE': '',
|
'REMOTE_POSTGRES_SSLMODE': '',
|
||||||
'THUMBOR_URL': '',
|
'THUMBOR_URL': '',
|
||||||
|
'THUMBNAIL_IMAGES': False,
|
||||||
'SENDFILE_BACKEND': None,
|
'SENDFILE_BACKEND': None,
|
||||||
|
|
||||||
# ToS/Privacy templates
|
# ToS/Privacy templates
|
||||||
|
|
|
@ -159,6 +159,7 @@ PUSH_NOTIFICATION_BOUNCER_URL = None
|
||||||
SLOW_QUERY_LOGS_STREAM = None
|
SLOW_QUERY_LOGS_STREAM = None
|
||||||
|
|
||||||
THUMBOR_URL = 'http://127.0.0.1:9995'
|
THUMBOR_URL = 'http://127.0.0.1:9995'
|
||||||
|
THUMBNAIL_IMAGES = True
|
||||||
|
|
||||||
# Logging the emails while running the tests adds them
|
# Logging the emails while running the tests adds them
|
||||||
# to /emails page.
|
# to /emails page.
|
||||||
|
|
Loading…
Reference in New Issue