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