thumbnails: Extract user_uploads_or_external as a function.

This is a prepartory commit for the upcoming changes. It was meaningful
to extract this one out because this function is essentially a condition
check on whether a given url is one of the user_uploads or an external
one. Based on its value we decide whether a url must be thumbnailed or
not and thus this function will also be used in an upcoming commit
patching lib/thumbnail.py to do the same check before thumbnail url
generation.
This commit is contained in:
Aditya Bansal
2018-09-01 17:09:16 +05:30
committed by Tim Abbott
parent 9a411a5765
commit 5d68bd92ad
2 changed files with 5 additions and 3 deletions

View File

@@ -18,6 +18,9 @@ from zerver.lib.camo import get_camo_url
def is_thumbor_enabled() -> bool:
return settings.THUMBOR_URL != ''
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/')):
return THUMBOR_EXTERNAL_TYPE