mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 16:14:02 +00:00
Thumbor and tc-aws have been dragging their feet on Python 3 support for years, and even the alphas and unofficial forks we’ve been running don’t seem to be maintained anymore. Depending on these projects is no longer viable for us. Signed-off-by: Anders Kaseorg <anders@zulip.com>
26 lines
765 B
Python
26 lines
765 B
Python
# See https://zulip.readthedocs.io/en/latest/subsystems/thumbnailing.html
|
|
import os
|
|
import sys
|
|
from urllib.parse import urljoin
|
|
|
|
from django.utils.http import url_has_allowed_host_and_scheme
|
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
sys.path.append(ZULIP_PATH)
|
|
|
|
from zerver.lib.camo import get_camo_url
|
|
|
|
|
|
def user_uploads_or_external(url: str) -> bool:
|
|
return not url_has_allowed_host_and_scheme(url, allowed_hosts=None) or url.startswith(
|
|
"/user_uploads/"
|
|
)
|
|
|
|
|
|
def generate_thumbnail_url(path: str, size: str = "0x0", is_camo_url: bool = False) -> str:
|
|
path = urljoin("/", path)
|
|
|
|
if url_has_allowed_host_and_scheme(path, allowed_hosts=None):
|
|
return path
|
|
return get_camo_url(path)
|