2025-01-03 00:48:18 +00:00
|
|
|
from pathlib import Path
|
2024-12-28 17:54:42 +00:00
|
|
|
|
2025-01-03 00:48:18 +00:00
|
|
|
from django.conf import settings
|
2025-01-03 12:36:39 +00:00
|
|
|
from django.http import Http404
|
2024-12-28 17:54:42 +00:00
|
|
|
from ninja_extra import ControllerBase, api_controller, route
|
|
|
|
|
2025-01-04 17:57:31 +00:00
|
|
|
from com.calendar import IcsCalendar
|
2025-01-03 00:48:18 +00:00
|
|
|
from core.views.files import send_raw_file
|
2024-12-28 17:54:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
@api_controller("/calendar")
|
|
|
|
class CalendarController(ControllerBase):
|
2025-01-03 00:48:18 +00:00
|
|
|
CACHE_FOLDER: Path = settings.MEDIA_ROOT / "com" / "calendars"
|
|
|
|
|
2024-12-28 17:54:42 +00:00
|
|
|
@route.get("/external.ics")
|
|
|
|
def calendar_external(self):
|
2025-01-03 12:36:39 +00:00
|
|
|
"""Return the ICS file of the AE Google Calendar
|
|
|
|
|
2025-01-04 17:57:31 +00:00
|
|
|
Because of Google's cors rules, we can't just do a request to google ics
|
2025-01-03 12:36:39 +00:00
|
|
|
from the frontend. Google is blocking CORS request in it's responses headers.
|
|
|
|
The only way to do it from the frontend is to use Google Calendar API with an API key
|
|
|
|
This is not especially desirable as your API key is going to be provided to the frontend.
|
|
|
|
|
|
|
|
This is why we have this backend based solution.
|
|
|
|
"""
|
|
|
|
if (calendar := IcsCalendar.get_external()) is not None:
|
|
|
|
return send_raw_file(calendar)
|
|
|
|
raise Http404
|
2024-12-28 17:54:42 +00:00
|
|
|
|
|
|
|
@route.get("/internal.ics")
|
|
|
|
def calendar_internal(self):
|
2025-01-03 12:56:40 +00:00
|
|
|
return send_raw_file(IcsCalendar.get_internal())
|