blob: c4b39897ebf78452585e0d9f6d3ff552d2550721 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package handlers
import (
"crypto/subtle"
"github.com/LMBishop/confplanner/api/dto"
"github.com/LMBishop/confplanner/pkg/calendar"
"github.com/LMBishop/confplanner/pkg/ical"
"github.com/gofiber/fiber/v2"
)
func GetIcal(icalService ical.Service, calendarService calendar.Service) fiber.Handler {
return func(c *fiber.Ctx) error {
name := c.Query("name")
key := c.Query("key")
if name == "" || key == "" {
return &dto.ErrorResponse{
Code: fiber.StatusBadRequest,
Message: "Both name and key must be specified",
}
}
calendar, err := calendarService.GetCalendarByName(name)
if err != nil {
return err
}
if subtle.ConstantTimeCompare([]byte(key), []byte(calendar.Key)) != 1 {
return &dto.ErrorResponse{
Code: fiber.StatusUnauthorized,
Message: "Invalid key",
}
}
ical, err := icalService.GenerateIcalForCalendar(*calendar)
if err != nil {
return err
}
return c.SendString(ical)
}
}
|