2022-12-30 16:55:47 +00:00
|
|
|
"""Validations"""
|
2023-07-23 18:50:44 +00:00
|
|
|
from typing import Optional
|
|
|
|
|
2024-04-07 15:22:29 +00:00
|
|
|
from bookwyrm.settings import BASE_URL
|
2022-12-30 16:55:47 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-04-07 15:22:29 +00:00
|
|
|
if not url.startswith(BASE_URL):
|
|
|
|
return None
|
2022-12-30 16:55:47 +00:00
|
|
|
|
2024-04-07 15:22:29 +00:00
|
|
|
return url
|