2021-05-07 00:38:24 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse, HttpResponseForbidden
|
2018-12-17 17:27:05 +01:00
|
|
|
from django.shortcuts import redirect
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2018-12-17 17:27:05 +01:00
|
|
|
from zerver.lib.camo import is_camo_url_valid
|
|
|
|
from zerver.lib.thumbnail import generate_thumbnail_url
|
|
|
|
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
def handle_camo_url(request: HttpRequest, digest: str, received_url: str) -> HttpResponse:
|
2020-10-30 01:59:56 +01:00
|
|
|
original_url = bytes.fromhex(received_url).decode()
|
2018-12-17 17:27:05 +01:00
|
|
|
if is_camo_url_valid(digest, original_url):
|
2021-08-14 02:21:00 +02:00
|
|
|
return redirect(generate_thumbnail_url(original_url))
|
2018-12-17 17:27:05 +01:00
|
|
|
else:
|
2021-05-07 00:38:24 +02:00
|
|
|
return HttpResponseForbidden("<p>Not a valid URL.</p>")
|