Initial commit 🌈

This commit is contained in:
Ben Sarmiento
2023-10-16 21:31:51 +02:00
commit da2c53bf86
15 changed files with 802 additions and 0 deletions

28
pkg/dav/response.go Normal file
View File

@@ -0,0 +1,28 @@
package dav
func Directory(path string) Response {
return Response{
Href: customPathEscape(path),
Propstat: PropStat{
Prop: Prop{
ResourceType: ResourceType{Collection: &struct{}{}},
},
Status: "HTTP/1.1 200 OK",
},
}
}
func File(path string, fileSize int, added string) Response {
return Response{
Href: customPathEscape(path),
Propstat: PropStat{
Prop: Prop{
ContentLength: fileSize,
IsHidden: 0,
CreationDate: added,
LastModified: added,
},
Status: "HTTP/1.1 200 OK",
},
}
}

31
pkg/dav/types.go Normal file
View File

@@ -0,0 +1,31 @@
package dav
import "encoding/xml"
type MultiStatus struct {
XMLName xml.Name `xml:"d:multistatus"`
XMLNS string `xml:"xmlns:d,attr"`
Response []Response `xml:"d:response"`
}
type Response struct {
Href string `xml:"d:href"`
Propstat PropStat `xml:"d:propstat"`
}
type PropStat struct {
Prop Prop `xml:"d:prop"`
Status string `xml:"d:status"`
}
type Prop struct {
ResourceType ResourceType `xml:"d:resourcetype"`
ContentLength int `xml:"d:getcontentlength"`
CreationDate string `xml:"d:creationdate"`
LastModified string `xml:"d:getlastmodified"`
IsHidden int `xml:"d:ishidden"`
}
type ResourceType struct {
Collection *struct{} `xml:"d:collection,omitempty"`
}

14
pkg/dav/util.go Normal file
View File

@@ -0,0 +1,14 @@
package dav
import (
"net/url"
"strings"
)
func customPathEscape(input string) string {
segments := strings.Split(input, "/")
for i, segment := range segments {
segments[i] = url.PathEscape(segment)
}
return strings.Join(segments, "/")
}