mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
thumbnails: Return original path if url is not supposed to be thumbnailed.
This commit is contained in:
parent
5d68bd92ad
commit
8324e2c976
@ -22,7 +22,7 @@ def user_uploads_or_external(url: str) -> bool:
|
||||
return url.startswith('http') or url.lstrip('/').startswith('user_uploads/')
|
||||
|
||||
def get_source_type(url: str) -> str:
|
||||
if not (url.startswith('/user_uploads/') or url.startswith('/user_avatars/')):
|
||||
if not url.startswith('/user_uploads/'):
|
||||
return THUMBOR_EXTERNAL_TYPE
|
||||
|
||||
local_uploads_dir = settings.LOCAL_UPLOADS_DIR
|
||||
@ -39,8 +39,7 @@ def generate_thumbnail_url(path: str, size: str='0x0') -> str:
|
||||
return get_camo_url(path)
|
||||
return path
|
||||
|
||||
# Ignore thumbnailing for static resources.
|
||||
if path.startswith('/static/'):
|
||||
if not user_uploads_or_external(path):
|
||||
return path
|
||||
|
||||
source_type = get_source_type(path)
|
||||
|
||||
@ -72,8 +72,7 @@ class ThumbnailTest(ZulipTestCase):
|
||||
# Test full size custom emoji image (for emoji link in messages case).
|
||||
result = self.client_get("/thumbnail?url=%s&size=full" % (quoted_emoji_url))
|
||||
self.assertEqual(result.status_code, 302, result)
|
||||
expected_part_url = get_file_path_urlpart(custom_emoji_url)
|
||||
self.assertIn(expected_part_url, result.url)
|
||||
self.assertIn(custom_emoji_url, result.url)
|
||||
|
||||
# Tests the /api/v1/thumbnail api endpoint with standard API auth
|
||||
self.logout()
|
||||
@ -215,8 +214,7 @@ class ThumbnailTest(ZulipTestCase):
|
||||
# Test full size custom emoji image (for emoji link in messages case).
|
||||
result = self.client_get("/thumbnail?url=%s&size=full" % (quoted_emoji_url))
|
||||
self.assertEqual(result.status_code, 302, result)
|
||||
expected_part_url = get_file_path_urlpart(custom_emoji_url)
|
||||
self.assertIn(expected_part_url, result.url)
|
||||
self.assertIn(custom_emoji_url, result.url)
|
||||
|
||||
# Tests the /api/v1/thumbnail api endpoint with HTTP basic auth.
|
||||
self.logout()
|
||||
|
||||
@ -40,9 +40,6 @@ def load(context, url, callback):
|
||||
if actual_url.startswith('/user_uploads/'): # type: ignore # python 2 type differs from python 3 type
|
||||
actual_url = actual_url[len('/user_uploads/'):]
|
||||
local_file_path_prefix = 'files/'
|
||||
elif actual_url.startswith('/user_avatars/'): # type: ignore # python 2 type differs from python 3 type
|
||||
actual_url = actual_url[len('/user_avatars/'):]
|
||||
local_file_path_prefix = 'avatars/'
|
||||
else:
|
||||
raise AssertionError("Unexpected local file.")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user