mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
Properly preview images from Dropbox photo albums.
Reported by jhurwitz (sorta). (imported from commit 8ae4c5f7af86c5492842142b89be8cab1a2c3fae)
This commit is contained in:
committed by
Jessica McKellar
parent
b80293c80d
commit
243c327d0a
@@ -178,12 +178,14 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
|
||||
return False
|
||||
|
||||
def dropbox_image(self, url):
|
||||
if not self.is_image(url):
|
||||
return None
|
||||
parsed_url = urlparse.urlparse(url)
|
||||
if (parsed_url.netloc == 'dropbox.com' or parsed_url.netloc.endswith('.dropbox.com')) \
|
||||
and (parsed_url.path.startswith('/s/') or parsed_url.path.startswith('/sh/')):
|
||||
return "%s?dl=1" % (url,)
|
||||
if (parsed_url.netloc == 'dropbox.com' or parsed_url.netloc.endswith('.dropbox.com')):
|
||||
if self.is_image(url) and (parsed_url.path.startswith('/s/')
|
||||
or parsed_url.path.startswith('/sh/')):
|
||||
return "%s?dl=1" % (url,)
|
||||
if parsed_url.path.startswith('/sc/'):
|
||||
# /sc/ is generally speaking a photo album, so let's unconditionally try to preview it
|
||||
return "%s?dl=1" % (url,)
|
||||
return None
|
||||
|
||||
def youtube_image(self, url):
|
||||
|
||||
@@ -192,6 +192,11 @@ class BugdownTest(TestCase):
|
||||
|
||||
self.assertEqual(converted, '<p>Look at my hilarious drawing: <a href="https://www.dropbox.com/sh/inlugx9d25r314h/JYwv59v4Jv/credit_card_rushmore.jpg" target="_blank" title="https://www.dropbox.com/sh/inlugx9d25r314h/JYwv59v4Jv/credit_card_rushmore.jpg">https://www.dropbox.com/sh/inlugx9d25r314h/JYwv59v4Jv/credit_card_rushmore.jpg</a></p>\n<div class="message_inline_image"><a href="https://www.dropbox.com/sh/inlugx9d25r314h/JYwv59v4Jv/credit_card_rushmore.jpg" target="_blank" title="https://www.dropbox.com/sh/inlugx9d25r314h/JYwv59v4Jv/credit_card_rushmore.jpg"><img src="https://www.dropbox.com/sh/inlugx9d25r314h/JYwv59v4Jv/credit_card_rushmore.jpg?dl=1"></a></div>')
|
||||
|
||||
# Test photo album previews
|
||||
msg = 'https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5'
|
||||
converted = bugdown_convert(msg)
|
||||
|
||||
self.assertEqual(converted, '<p><a href="https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5" target="_blank" title="https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5">https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5</a></p>\n<div class="message_inline_image"><a href="https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5" target="_blank" title="https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5"><img src="https://www.dropbox.com/sc/tditp9nitko60n5/03rEiZldy5?dl=1"></a></div>')
|
||||
|
||||
# Make sure we're not overzealous in our conversion:
|
||||
msg = 'Look at the new dropbox logo: https://www.dropbox.com/static/images/home_logo.png'
|
||||
|
||||
Reference in New Issue
Block a user