mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 11:22:04 +00:00
Fixes #2665. Regenerated by tabbott with `lint --fix` after a rebase and change in parameters. Note from tabbott: In a few cases, this converts technical debt in the form of unsorted imports into different technical debt in the form of our largest files having very long, ugly import sequences at the start. I expect this change will increase pressure for us to split those files, which isn't a bad thing. Signed-off-by: Anders Kaseorg <anders@zulip.com>
24 lines
893 B
Python
24 lines
893 B
Python
import binascii
|
|
|
|
from django.conf import settings
|
|
from django.http import HttpRequest, HttpResponse, HttpResponseForbidden, HttpResponseNotFound
|
|
from django.shortcuts import redirect
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from zerver.lib.camo import is_camo_url_valid
|
|
from zerver.lib.thumbnail import generate_thumbnail_url
|
|
|
|
|
|
def handle_camo_url(request: HttpRequest, digest: str,
|
|
received_url: str) -> HttpResponse:
|
|
if not settings.THUMBOR_SERVES_CAMO:
|
|
return HttpResponseNotFound()
|
|
|
|
hex_encoded_url = received_url.encode('utf-8')
|
|
hex_decoded_url = binascii.a2b_hex(hex_encoded_url)
|
|
original_url = hex_decoded_url.decode('utf-8')
|
|
if is_camo_url_valid(digest, original_url):
|
|
return redirect(generate_thumbnail_url(original_url, is_camo_url=True))
|
|
else:
|
|
return HttpResponseForbidden(_("<p>Not a valid URL.</p>"))
|