2022-12-30 17:55:47 +01:00
|
|
|
"""Validations"""
|
|
|
|
from bookwyrm.settings import DOMAIN, USE_HTTPS
|
|
|
|
|
|
|
|
|
|
|
|
def validate_url_domain(url, default="/"):
|
|
|
|
"""Basic check that the URL starts with the instance domain name"""
|
2023-01-01 20:51:23 +01:00
|
|
|
if not url:
|
|
|
|
return default
|
|
|
|
|
|
|
|
if url in ("/", default):
|
2022-12-30 17:55:47 +01:00
|
|
|
return url
|
|
|
|
|
|
|
|
protocol = "https://" if USE_HTTPS else "http://"
|
|
|
|
origin = f"{protocol}{DOMAIN}"
|
|
|
|
|
|
|
|
if url.startswith(origin):
|
|
|
|
return url
|
|
|
|
|
|
|
|
return default
|