aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorLibravatarLibravatar Simon Ser <[email protected]> 2023-12-27 23:32:49 +0100
committerLibravatarLibravatar Simon Ser <[email protected]> 2023-12-27 23:32:49 +0100
commit84a72320e2309c6e3f60574e22cb61a5eefd9c15 (patch)
treed92788333d2ce03b00110abb5a6f6715113fa8e8 /plugins
parent39d5377855b54653ef43bceb5e317bbaec87ca15 (diff)
downloadalps-84a72320e2309c6e3f60574e22cb61a5eefd9c15.tar.gz
alps-84a72320e2309c6e3f60574e22cb61a5eefd9c15.tar.bz2
alps-84a72320e2309c6e3f60574e22cb61a5eefd9c15.zip
Upgrade go-webdav
Diffstat (limited to 'plugins')
-rw-r--r--plugins/caldav/caldav.go9
-rw-r--r--plugins/caldav/routes.go22
-rw-r--r--plugins/carddav/plugin.go15
-rw-r--r--plugins/carddav/routes.go16
4 files changed, 32 insertions, 30 deletions
diff --git a/plugins/caldav/caldav.go b/plugins/caldav/caldav.go
index 05d57fe..07aa162 100644
--- a/plugins/caldav/caldav.go
+++ b/plugins/caldav/caldav.go
@@ -1,6 +1,7 @@
package alpscaldav
import (
+ "context"
"fmt"
"net/http"
"net/url"
@@ -34,23 +35,23 @@ func newClient(u *url.URL, session *alps.Session) (*caldav.Client, error) {
return c, nil
}
-func getCalendar(u *url.URL, session *alps.Session) (*caldav.Client, *caldav.Calendar, error) {
+func getCalendar(ctx context.Context, u *url.URL, session *alps.Session) (*caldav.Client, *caldav.Calendar, error) {
c, err := newClient(u, session)
if err != nil {
return nil, nil, err
}
- principal, err := c.FindCurrentUserPrincipal()
+ principal, err := c.FindCurrentUserPrincipal(ctx)
if err != nil {
return nil, nil, fmt.Errorf("failed to query CalDAV principal: %v", err)
}
- calendarHomeSet, err := c.FindCalendarHomeSet(principal)
+ calendarHomeSet, err := c.FindCalendarHomeSet(ctx, principal)
if err != nil {
return nil, nil, fmt.Errorf("failed to query CalDAV calendar home set: %v", err)
}
- calendars, err := c.FindCalendars(calendarHomeSet)
+ calendars, err := c.FindCalendars(ctx, calendarHomeSet)
if err != nil {
return nil, nil, fmt.Errorf("failed to find calendars: %v", err)
}
diff --git a/plugins/caldav/routes.go b/plugins/caldav/routes.go
index d551434..3e283bd 100644
--- a/plugins/caldav/routes.go
+++ b/plugins/caldav/routes.go
@@ -96,7 +96,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
end := start.AddDate(0, 1, 0)
// TODO: multi-calendar support
- c, calendar, err := getCalendar(u, ctx.Session)
+ c, calendar, err := getCalendar(ctx.Request().Context(), u, ctx.Session)
if err != nil {
return err
}
@@ -125,7 +125,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
}},
},
}
- events, err := c.QueryCalendar(calendar.Path, &query)
+ events, err := c.QueryCalendar(ctx.Request().Context(), calendar.Path, &query)
if err != nil {
return fmt.Errorf("failed to query calendar: %v", err)
}
@@ -209,7 +209,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
end := start.AddDate(0, 0, 1)
// TODO: multi-calendar support
- c, calendar, err := getCalendar(u, ctx.Session)
+ c, calendar, err := getCalendar(ctx.Request().Context(), u, ctx.Session)
if err != nil {
return err
}
@@ -238,7 +238,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
}},
},
}
- events, err := c.QueryCalendar(calendar.Path, &query)
+ events, err := c.QueryCalendar(ctx.Request().Context(), calendar.Path, &query)
if err != nil {
return fmt.Errorf("failed to query calendar: %v", err)
}
@@ -260,7 +260,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
return err
}
- c, calendar, err := getCalendar(u, ctx.Session)
+ c, calendar, err := getCalendar(ctx.Request().Context(), u, ctx.Session)
if err != nil {
return err
}
@@ -283,7 +283,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
},
}
- events, err := c.MultiGetCalendar(path, &multiGet)
+ events, err := c.MultiGetCalendar(ctx.Request().Context(), path, &multiGet)
if err != nil {
return fmt.Errorf("failed to multi-get calendar: %v", err)
}
@@ -306,7 +306,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
return err
}
- c, calendar, err := getCalendar(u, ctx.Session)
+ c, calendar, err := getCalendar(ctx.Request().Context(), u, ctx.Session)
if err != nil {
return err
}
@@ -314,7 +314,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
var co *caldav.CalendarObject
var event *ical.Event
if calendarObjectPath != "" {
- co, err = c.GetCalendarObject(calendarObjectPath)
+ co, err = c.GetCalendarObject(ctx.Request().Context(), calendarObjectPath)
if err != nil {
return fmt.Errorf("failed to get CalDAV event: %v", err)
}
@@ -377,7 +377,7 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
} else {
p = path.Join(calendar.Path, newID.String()+".ics")
}
- co, err = c.PutCalendarObject(p, cal)
+ co, err = c.PutCalendarObject(ctx.Request().Context(), p, cal)
if err != nil {
return fmt.Errorf("failed to put calendar object: %v", err)
}
@@ -407,12 +407,12 @@ func registerRoutes(p *alps.GoPlugin, u *url.URL) {
return err
}
- c, _, err := getCalendar(u, ctx.Session)
+ c, _, err := getCalendar(ctx.Request().Context(), u, ctx.Session)
if err != nil {
return err
}
- if err := c.RemoveAll(path); err != nil {
+ if err := c.RemoveAll(ctx.Request().Context(), path); err != nil {
return fmt.Errorf("failed to delete calendar object: %v", err)
}
diff --git a/plugins/carddav/plugin.go b/plugins/carddav/plugin.go
index 5f1667e..54f3046 100644
--- a/plugins/carddav/plugin.go
+++ b/plugins/carddav/plugin.go
@@ -1,6 +1,7 @@
package alpscarddav
import (
+ "context"
"fmt"
"net/http"
"net/url"
@@ -40,7 +41,7 @@ func (p *plugin) client(session *alps.Session) (*carddav.Client, error) {
return newClient(p.url, session)
}
-func (p *plugin) clientWithAddressBook(session *alps.Session) (*carddav.Client, *carddav.AddressBook, error) {
+func (p *plugin) clientWithAddressBook(ctx context.Context, session *alps.Session) (*carddav.Client, *carddav.AddressBook, error) {
c, err := newClient(p.url, session)
if err != nil {
return nil, nil, fmt.Errorf("failed to create CardDAV client: %v", err)
@@ -48,12 +49,12 @@ func (p *plugin) clientWithAddressBook(session *alps.Session) (*carddav.Client,
homeSet, ok := p.homeSetCache[session.Username()]
if !ok {
- principal, err := c.FindCurrentUserPrincipal()
+ principal, err := c.FindCurrentUserPrincipal(ctx)
if err != nil {
return nil, nil, fmt.Errorf("failed to query CardDAV principal: %v", err)
}
- homeSet, err = c.FindAddressBookHomeSet(principal)
+ homeSet, err = c.FindAddressBookHomeSet(ctx, principal)
if err != nil {
return nil, nil, fmt.Errorf("failed to query CardDAV address book home set: %v", err)
}
@@ -62,7 +63,7 @@ func (p *plugin) clientWithAddressBook(session *alps.Session) (*carddav.Client,
// TODO: evict entries from the cache if it's getting too big
}
- addressBooks, err := c.FindAddressBooks(homeSet)
+ addressBooks, err := c.FindAddressBooks(ctx, homeSet)
if err != nil {
return nil, nil, fmt.Errorf("failed to query CardDAV address books: %v", err)
}
@@ -86,7 +87,7 @@ func newPlugin(srv *alps.Server) (alps.Plugin, error) {
u.Scheme = "http"
}
if u.Scheme == "" {
- s, err := carddav.Discover(u.Host)
+ s, err := carddav.DiscoverContextURL(context.Background(), u.Host)
if err != nil {
srv.Logger().Printf("carddav: failed to discover CardDAV server: %v", err)
return nil, nil
@@ -114,7 +115,7 @@ func newPlugin(srv *alps.Server) (alps.Plugin, error) {
p.Inject("compose.html", func(ctx *alps.Context, _data alps.RenderData) error {
data := _data.(*alpsbase.ComposeRenderData)
- c, addressBook, err := p.clientWithAddressBook(ctx.Session)
+ c, addressBook, err := p.clientWithAddressBook(ctx.Request().Context(), ctx.Session)
if err == errNoAddressBook {
return nil
} else if err != nil {
@@ -129,7 +130,7 @@ func newPlugin(srv *alps.Server) (alps.Plugin, error) {
Name: vcard.FieldEmail,
}},
}
- addrs, err := c.QueryAddressBook(addressBook.Path, &query)
+ addrs, err := c.QueryAddressBook(ctx.Request().Context(), addressBook.Path, &query)
if err != nil {
return fmt.Errorf("failed to query CardDAV addresses: %v", err)
}
diff --git a/plugins/carddav/routes.go b/plugins/carddav/routes.go
index 6c8a85f..c51ed23 100644
--- a/plugins/carddav/routes.go
+++ b/plugins/carddav/routes.go
@@ -47,7 +47,7 @@ func registerRoutes(p *plugin) {
p.GET("/contacts", func(ctx *alps.Context) error {
queryText := ctx.QueryParam("query")
- c, addressBook, err := p.clientWithAddressBook(ctx.Session)
+ c, addressBook, err := p.clientWithAddressBook(ctx.Request().Context(), ctx.Session)
if err != nil {
return err
}
@@ -78,7 +78,7 @@ func registerRoutes(p *plugin) {
}
}
- aos, err := c.QueryAddressBook(addressBook.Path, &query)
+ aos, err := c.QueryAddressBook(ctx.Request().Context(), addressBook.Path, &query)
if err != nil {
return fmt.Errorf("failed to query CardDAV addresses: %v", err)
}
@@ -97,7 +97,7 @@ func registerRoutes(p *plugin) {
return err
}
- c, addressBook, err := p.clientWithAddressBook(ctx.Session)
+ c, addressBook, err := p.clientWithAddressBook(ctx.Request().Context(), ctx.Session)
if err != nil {
return err
}
@@ -111,7 +111,7 @@ func registerRoutes(p *plugin) {
},
},
}
- aos, err := c.MultiGetAddressBook(path, &multiGet)
+ aos, err := c.MultiGetAddressBook(ctx.Request().Context(), path, &multiGet)
if err != nil {
return fmt.Errorf("failed to query CardDAV address: %v", err)
}
@@ -133,7 +133,7 @@ func registerRoutes(p *plugin) {
return err
}
- c, addressBook, err := p.clientWithAddressBook(ctx.Session)
+ c, addressBook, err := p.clientWithAddressBook(ctx.Request().Context(), ctx.Session)
if err != nil {
return err
}
@@ -141,7 +141,7 @@ func registerRoutes(p *plugin) {
var ao *carddav.AddressObject
var card vcard.Card
if addressObjectPath != "" {
- ao, err = c.GetAddressObject(addressObjectPath)
+ ao, err = c.GetAddressObject(ctx.Request().Context(), addressObjectPath)
if err != nil {
return fmt.Errorf("failed to query CardDAV address: %v", err)
}
@@ -194,7 +194,7 @@ func registerRoutes(p *plugin) {
} else {
p = path.Join(addressBook.Path, id.String()+".vcf")
}
- ao, err = c.PutAddressObject(p, card)
+ ao, err = c.PutAddressObject(ctx.Request().Context(), p, card)
if err != nil {
return fmt.Errorf("failed to put address object: %v", err)
}
@@ -227,7 +227,7 @@ func registerRoutes(p *plugin) {
return err
}
- if err := c.RemoveAll(path); err != nil {
+ if err := c.RemoveAll(ctx.Request().Context(), path); err != nil {
return fmt.Errorf("failed to delete address object: %v", err)
}