camo: Add endpoint to handle camo requests.

This endpoint serves requests which might originate from an image
preview link which had an http url and the message holding the image
link was rendered before we introduced thumbnailing. In that case
we would have used a camo proxy to proxy http content over https and
avoid mix content warnings.

In near future, we plan to drop use of camo and just rely on thumbor
to serve such images. This endpoint helps maintain backward
compatibility for links which were already rendered.
This commit is contained in:
Aditya Bansal
2018-12-17 21:57:05 +05:30
committed by Tim Abbott
parent 3ee69f3da9
commit 079dfadf1a
8 changed files with 69 additions and 3 deletions

View File

@@ -30,7 +30,9 @@ def get_source_type(url: str) -> str:
return THUMBOR_LOCAL_FILE_TYPE
return THUMBOR_S3_TYPE
def generate_thumbnail_url(path: str, size: str='0x0') -> str:
def generate_thumbnail_url(path: str,
size: str='0x0',
is_camo_url: bool=False) -> str:
if not (path.startswith('https://') or path.startswith('http://')):
path = '/' + path
@@ -48,14 +50,18 @@ def generate_thumbnail_url(path: str, size: str='0x0') -> str:
width, height = map(int, size.split('x'))
crypto = CryptoURL(key=settings.THUMBOR_KEY)
smart_crop_enabled = True
apply_filters = ['no_upscale()']
if is_camo_url:
smart_crop_enabled = False
apply_filters.append('quality(100)')
if size != '0x0':
apply_filters.append('sharpen(0.5,0.2,true)')
encrypted_url = crypto.generate(
width=width,
height=height,
smart=True,
smart=smart_crop_enabled,
filters=apply_filters,
image_url=image_url
)