mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
caldav: parse iCal data
This commit is contained in:
parent
4eb8396edb
commit
baf63fb1b7
@ -5,6 +5,8 @@ package caldav
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/luxifer/ical"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Calendar struct {
|
type Calendar struct {
|
||||||
@ -39,5 +41,5 @@ type CalendarObject struct {
|
|||||||
Path string
|
Path string
|
||||||
ModTime time.Time
|
ModTime time.Time
|
||||||
ETag string
|
ETag string
|
||||||
Data []byte
|
Data *ical.Calendar
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package caldav
|
package caldav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/emersion/go-webdav"
|
"github.com/emersion/go-webdav"
|
||||||
"github.com/emersion/go-webdav/internal"
|
"github.com/emersion/go-webdav/internal"
|
||||||
|
"github.com/luxifer/ical"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client provides access to a remote CardDAV server.
|
// Client provides access to a remote CardDAV server.
|
||||||
@ -178,11 +180,22 @@ func decodeCalendarObjectList(ms *internal.Multistatus) ([]CalendarObject, error
|
|||||||
return nil, err
|
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{
|
addrs = append(addrs, CalendarObject{
|
||||||
Path: path,
|
Path: path,
|
||||||
ModTime: time.Time(getLastMod.LastModified),
|
ModTime: time.Time(getLastMod.LastModified),
|
||||||
ETag: string(getETag.ETag),
|
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
|
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 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/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