mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-16 09:38:49 +02:00
fix:#16 added userAgent and fixed logging for room ical
This commit is contained in:
@ -5,7 +5,6 @@ import (
|
||||
"github.com/pocketbase/pocketbase"
|
||||
pb "htwkalender/common/genproto/modules"
|
||||
"htwkalender/data-manager/service/db"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
type RoomServiceHandler struct {
|
||||
@ -19,9 +18,6 @@ func (s *RoomServiceHandler) GetRoomEvents(ctx context.Context, in *pb.GetRoomRe
|
||||
"Protobuf - GetRoomEvents",
|
||||
"room", in.Room,
|
||||
)
|
||||
|
||||
slog.Error("GetRoomEvents", "room", in.Room)
|
||||
|
||||
// get events from database by room
|
||||
events, err := db.GetRoomSchedule(s.app, in.Room)
|
||||
if err != nil {
|
||||
|
@ -107,7 +107,7 @@ func CreateFeed(app model.AppType, modules []model.FeedCollection) (string, erro
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func FeedRoom(app model.AppType, room string) (string, string, error) {
|
||||
func FeedRoom(app model.AppType, room string, userAgent string) (string, string, error) {
|
||||
|
||||
// Get all events for room
|
||||
events, err := htwkalenderGrpc.GetEventsByRoom(room, app.GrpcClient)
|
||||
@ -121,7 +121,7 @@ func FeedRoom(app model.AppType, room string) (string, string, error) {
|
||||
// Generate one Hash for E-TAG from all events
|
||||
etag := functions.HashString(events.String())
|
||||
|
||||
cal := GenerateIcalFeed(events, map[string]model.FeedCollection{}, "")
|
||||
cal := GenerateIcalFeed(events, map[string]model.FeedCollection{}, userAgent)
|
||||
icalFeed := &model.FeedModel{Content: cal.Serialize(), ExpiresAt: model.JSONTime(time.Now().Add(expirationTime))}
|
||||
|
||||
return icalFeed.Content, etag, nil
|
||||
|
@ -123,8 +123,9 @@ func AddFeedRoutes(app model.AppType) {
|
||||
app.Fiber.Get("/api/feed/room", func(c fiber.Ctx) error {
|
||||
room := c.Query("id")
|
||||
ifNoneMatch := c.Get("If-None-Match")
|
||||
userAgent := c.Get("User-Agent")
|
||||
|
||||
results, etag, err := ical.FeedRoom(app, room)
|
||||
results, etag, err := ical.FeedRoom(app, room, userAgent)
|
||||
if err != nil {
|
||||
slog.Error("Failed to get feed", "error", err, "room", room)
|
||||
return c.SendStatus(fiber.StatusNotFound)
|
||||
@ -144,10 +145,12 @@ func AddFeedRoutes(app model.AppType) {
|
||||
app.Fiber.Head("/api/feed", func(c fiber.Ctx) error {
|
||||
return c.JSON(http.StatusOK, "")
|
||||
})
|
||||
app.Fiber.Head("/api/feed/room", func(c fiber.Ctx) error { return c.JSON(http.StatusOK, "") })
|
||||
|
||||
app.Fiber.Add([]string{"PROPFIND"}, "/api/feed", func(c fiber.Ctx) error {
|
||||
return c.JSON(http.StatusOK, "")
|
||||
})
|
||||
app.Fiber.Add([]string{"PROPFIND"}, "/api/feed/room", func(c fiber.Ctx) error { return c.JSON(http.StatusOK, "") })
|
||||
|
||||
// Route for Thunderbird to get calendar server information
|
||||
// Response is a 200 OK without additional content
|
||||
|
Reference in New Issue
Block a user