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
|
|
|
|
|
|
|
|
|
2024-04-02 12:27:47 +00:00
|
|
|
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"""
|
2024-04-02 12:27:47 +00:00
|
|
|
if url is None:
|
2023-03-20 17:25:38 +00:00
|
|
|
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
|
|
|
|
|
2023-03-20 17:25:38 +00:00
|
|
|
return None
|