diff options
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 4 | ||||
-rw-r--r-- | plugins/caldav/public/calendar.html | 2 | ||||
-rw-r--r-- | plugins/caldav/routes.go | 41 |
4 files changed, 29 insertions, 20 deletions
@@ -14,7 +14,7 @@ require ( github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 github.com/emersion/go-smtp v0.13.0 github.com/emersion/go-vcard v0.0.0-20200508080525-dd3110a24ec2 - github.com/emersion/go-webdav v0.3.0 + github.com/emersion/go-webdav v0.3.1-0.20200513144525-a4e0e8100397 github.com/google/uuid v1.1.1 github.com/gorilla/css v1.0.0 // indirect github.com/labstack/echo/v4 v4.1.16 @@ -40,8 +40,8 @@ github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7 h1:SE+tcd+0kn0cT github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM= github.com/emersion/go-vcard v0.0.0-20200508080525-dd3110a24ec2 h1:g1RgqggIPPkEBubnOxAbIglxjMsP0aHPO2ryigBHu2s= github.com/emersion/go-vcard v0.0.0-20200508080525-dd3110a24ec2/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM= -github.com/emersion/go-webdav v0.3.0 h1:I1J9xf7fa1NxXFWCKyN5Ju3Sa3jJeNMI3uJQKHYg0SY= -github.com/emersion/go-webdav v0.3.0/go.mod h1:uSM1VveeKtogBVWaYccTksToczooJ0rrVGNsgnDsr4Q= +github.com/emersion/go-webdav v0.3.1-0.20200513144525-a4e0e8100397 h1:XVnGMemAywvBnsUAIsx4v+avxzauS00Mf9l9oM9olFc= +github.com/emersion/go-webdav v0.3.1-0.20200513144525-a4e0e8100397/go.mod h1:uSM1VveeKtogBVWaYccTksToczooJ0rrVGNsgnDsr4Q= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= diff --git a/plugins/caldav/public/calendar.html b/plugins/caldav/public/calendar.html index 7787bb1..8a0a390 100644 --- a/plugins/caldav/public/calendar.html +++ b/plugins/caldav/public/calendar.html @@ -14,7 +14,7 @@ {{range .Events}} {{$event := index .Data.Events 0}} <li> - <a href="/calendar/{{$event.Props.Text "UID" | pathescape}}">{{$event.Props.Text "SUMMARY"}}</a> + <a href="/calendar/{{$event.Path | pathescape}}">{{$event.Props.Text "SUMMARY"}}</a> ({{$event.DateTimeStart nil | formatdate}} — {{$event.DateTimeEnd nil | formatdate}}) </li> {{end}} diff --git a/plugins/caldav/routes.go b/plugins/caldav/routes.go index ee18574..9fb9db3 100644 --- a/plugins/caldav/routes.go +++ b/plugins/caldav/routes.go @@ -8,6 +8,7 @@ import ( "git.sr.ht/~emersion/alps" "github.com/emersion/go-webdav/caldav" + "github.com/labstack/echo/v4" ) type CalendarRenderData struct { @@ -26,6 +27,15 @@ type EventRenderData struct { var monthPageLayout = "2006-01" +func parseObjectPath(s string) (string, error) { + p, err := url.PathUnescape(s) + if err != nil { + err = fmt.Errorf("failed to parse path: %v", err) + return "", echo.NewHTTPError(http.StatusBadRequest, err) + } + return string(p), nil +} + func registerRoutes(p *alps.GoPlugin, u *url.URL) { p.GET("/calendar", func(ctx *alps.Context) error { var start time.Time @@ -86,15 +96,23 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) { }) }) - p.GET("/calendar/:uid", func(ctx *alps.Context) error { - uid := ctx.Param("uid") + p.GET("/calendar/:path", func(ctx *alps.Context) error { + path, err := parseObjectPath(ctx.Param("path")) + if err != nil { + return err + } + + c, err := newClient(u, ctx.Session) + if err != nil { + return err + } c, calendar, err := getCalendar(u, ctx.Session) if err != nil { return err } - query := caldav.CalendarQuery{ + multiGet := caldav.CalendarMultiGet{ CompRequest: caldav.CalendarCompRequest{ Name: "VCALENDAR", Props: []string{"VERSION"}, @@ -110,23 +128,14 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) { }, }}, }, - CompFilter: caldav.CompFilter{ - Name: "VCALENDAR", - Comps: []caldav.CompFilter{{ - Name: "VEVENT", - Props: []caldav.PropFilter{{ - Name: "UID", - TextMatch: &caldav.TextMatch{Text: uid}, - }}, - }}, - }, } - events, err := c.QueryCalendar(calendar.Path, &query) + + events, err := c.MultiGetCalendar(path, &multiGet) if err != nil { - return fmt.Errorf("failed to query calendar: %v", err) + return fmt.Errorf("failed to multi-get calendar: %v", err) } if len(events) != 1 { - return fmt.Errorf("expected exactly one calendar object with UID %q, got %v", uid, len(events)) + return fmt.Errorf("expected exactly one calendar object with path %q, got %v", path, len(events)) } event := &events[0] |