mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-05-19 08:48:19 +00:00
19 lines
429 B
Python
19 lines
429 B
Python
"""Validations"""
|
|
from typing import Optional
|
|
|
|
from bookwyrm.settings import DOMAIN, USE_HTTPS
|
|
|
|
|
|
def validate_url_domain(url: Optional[str]) -> Optional[str]:
|
|
"""Basic check that the URL starts with the instance domain name"""
|
|
if url is None:
|
|
return None
|
|
|
|
protocol = "https://" if USE_HTTPS else "http://"
|
|
origin = f"{protocol}{DOMAIN}"
|
|
|
|
if url.startswith(origin):
|
|
return url
|
|
|
|
return None
|