mirror of https://github.com/zulip/zulip.git
14 lines
565 B
Python
14 lines
565 B
Python
from django.http import HttpRequest, HttpResponse, HttpResponseForbidden
|
|
from django.shortcuts import redirect
|
|
|
|
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:
|
|
original_url = bytes.fromhex(received_url).decode()
|
|
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>")
|