bookwyrm/bookwyrm/utils/validate.py

19 lines
429 B
Python
Raw Normal View History

2022-12-30 16:55:47 +00:00
"""Validations"""
2023-07-23 18:50:44 +00:00
from typing import Optional
2022-12-30 16:55:47 +00:00
from bookwyrm.settings import DOMAIN, USE_HTTPS
def validate_url_domain(url: Optional[str]) -> Optional[str]:
2022-12-30 16:55:47 +00:00
"""Basic check that the URL starts with the instance domain name"""
if url is None:
return None
2023-01-01 19:51:23 +00:00
2022-12-30 16:55:47 +00:00
protocol = "https://" if USE_HTTPS else "http://"
origin = f"{protocol}{DOMAIN}"
if url.startswith(origin):
return url
return None