aboutsummaryrefslogtreecommitdiff
path: root/plugins/caldav
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-05-13 16:48:03 +0200
committerSimon Ser <contact@emersion.fr>2020-05-13 16:48:03 +0200
commit0191b739969e00cdba0faa5a05159fd5f83d5d9e (patch)
treecb0eed33b7100993acc35a44e18f0085fe98822b /plugins/caldav
parent59547f7fb7ba0b7cf264ad8bde164aae89a23b5e (diff)
downloadalps-0191b739969e00cdba0faa5a05159fd5f83d5d9e.tar.gz
alps-0191b739969e00cdba0faa5a05159fd5f83d5d9e.zip
plugins/caldav: switch to path-based URLs
UIDs are not first-class WebDAV citizens and would require two roundtrips for most operations.
Diffstat (limited to 'plugins/caldav')
-rw-r--r--plugins/caldav/public/calendar.html2
-rw-r--r--plugins/caldav/routes.go41
2 files changed, 26 insertions, 17 deletions
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]