mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
caldav: parse iCal data
This commit is contained in:
parent
4eb8396edb
commit
baf63fb1b7
@ -5,6 +5,8 @@ package caldav
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/luxifer/ical"
|
||||
)
|
||||
|
||||
type Calendar struct {
|
||||
@ -39,5 +41,5 @@ type CalendarObject struct {
|
||||
Path string
|
||||
ModTime time.Time
|
||||
ETag string
|
||||
Data []byte
|
||||
Data *ical.Calendar
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
package caldav
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/emersion/go-webdav"
|
||||
"github.com/emersion/go-webdav/internal"
|
||||
"github.com/luxifer/ical"
|
||||
)
|
||||
|
||||
// Client provides access to a remote CardDAV server.
|
||||
@ -178,11 +180,22 @@ func decodeCalendarObjectList(ms *internal.Multistatus) ([]CalendarObject, error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Normalize line endings
|
||||
// TODO: make the ical package less strict
|
||||
b := calData.Data
|
||||
b = bytes.ReplaceAll(b, []byte{'\r', '\n'}, []byte{'\n'})
|
||||
b = bytes.ReplaceAll(b, []byte{'\n'}, []byte{'\r', '\n'})
|
||||
|
||||
data, err := ical.Parse(bytes.NewReader(b), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
addrs = append(addrs, CalendarObject{
|
||||
Path: path,
|
||||
ModTime: time.Time(getLastMod.LastModified),
|
||||
ETag: string(getETag.ETag),
|
||||
Data: calData.Data,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
|
5
go.mod
5
go.mod
@ -2,4 +2,7 @@ module github.com/emersion/go-webdav
|
||||
|
||||
go 1.13
|
||||
|
||||
require github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7
|
||||
require (
|
||||
github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7
|
||||
github.com/luxifer/ical v0.0.0-20191105105432-84b768eb6395
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -1,2 +1,4 @@
|
||||
github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7 h1:SE+tcd+0kn0cT4MqTo66gmkjqWHF1Z+Yha5/rhLs/H8=
|
||||
github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM=
|
||||
github.com/luxifer/ical v0.0.0-20191105105432-84b768eb6395 h1:H7Rbug09BDCzr6k/PASDjSMjbJGzXswwqesaDiBNJz8=
|
||||
github.com/luxifer/ical v0.0.0-20191105105432-84b768eb6395/go.mod h1:TGCe94U3u9fXQl4yHJ8W87z1czj057aVLxYnFYTDC08=
|
||||
|
Loading…
Reference in New Issue
Block a user