From 89149b38c8d10d4db457614450517e4ab6d57062 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 27 Feb 2020 12:17:23 +0100 Subject: plugins/carddav: use paths instead of UIDs in URLs --- plugins/carddav/carddav.go | 16 +++++ plugins/carddav/plugin.go | 4 ++ plugins/carddav/public/address-book.html | 2 +- plugins/carddav/public/address-object.html | 2 +- plugins/carddav/public/update-address-object.html | 4 +- plugins/carddav/routes.go | 80 +++++++++++------------ 6 files changed, 62 insertions(+), 46 deletions(-) (limited to 'plugins/carddav') diff --git a/plugins/carddav/carddav.go b/plugins/carddav/carddav.go index 0c1a06d..2509872 100644 --- a/plugins/carddav/carddav.go +++ b/plugins/carddav/carddav.go @@ -28,3 +28,19 @@ func newClient(u *url.URL, session *koushin.Session) (*carddav.Client, error) { } return carddav.NewClient(&http.Client{Transport: &rt}, u.String()) } + +type AddressObject struct { + *carddav.AddressObject +} + +func newAddressObjectList(aos []carddav.AddressObject) []AddressObject { + l := make([]AddressObject, len(aos)) + for i := range aos { + l[i] = AddressObject{&aos[i]} + } + return l +} + +func (ao AddressObject) URL() string { + return "/contacts/" + url.PathEscape(ao.Path) +} diff --git a/plugins/carddav/plugin.go b/plugins/carddav/plugin.go index 5afdde2..3002da1 100644 --- a/plugins/carddav/plugin.go +++ b/plugins/carddav/plugin.go @@ -37,6 +37,10 @@ type plugin struct { homeSetCache map[string]string } +func (p *plugin) client(session *koushin.Session) (*carddav.Client, error) { + return newClient(p.url, session) +} + func (p *plugin) clientWithAddressBook(session *koushin.Session) (*carddav.Client, *carddav.AddressBook, error) { c, err := newClient(p.url, session) if err != nil { diff --git a/plugins/carddav/public/address-book.html b/plugins/carddav/public/address-book.html index 3c31017..d4e13b9 100644 --- a/plugins/carddav/public/address-book.html +++ b/plugins/carddav/public/address-book.html @@ -17,7 +17,7 @@