2018-03-08 09:37:09 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2019-12-20 02:58:53 +01:00
|
|
|
from urllib.parse import urljoin
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2021-04-16 00:59:20 +02:00
|
|
|
from django.utils.http import url_has_allowed_host_and_scheme
|
2018-03-08 09:37:09 +01:00
|
|
|
|
2020-04-12 19:44:42 +02:00
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
2018-03-08 09:37:09 +01:00
|
|
|
sys.path.append(ZULIP_PATH)
|
|
|
|
|
|
|
|
from zerver.lib.camo import get_camo_url
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-09-01 13:39:16 +02:00
|
|
|
def user_uploads_or_external(url: str) -> bool:
|
2021-04-16 00:59:20 +02:00
|
|
|
return not url_has_allowed_host_and_scheme(url, allowed_hosts=None) or url.startswith(
|
|
|
|
"/user_uploads/"
|
|
|
|
)
|
2018-09-01 13:39:16 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-08-14 02:21:00 +02:00
|
|
|
def generate_thumbnail_url(path: str, size: str = "0x0") -> str:
|
2019-12-12 01:28:29 +01:00
|
|
|
path = urljoin("/", path)
|
2018-03-08 09:37:09 +01:00
|
|
|
|
2021-05-07 00:38:24 +02:00
|
|
|
if url_has_allowed_host_and_scheme(path, allowed_hosts=None):
|
2019-12-20 02:58:53 +01:00
|
|
|
return path
|
2021-05-07 00:38:24 +02:00
|
|
|
return get_camo_url(path)
|