Files
zurg/pkg/dav/response.go
Ben Adrian Sarmiento 9053880623 Fix windows bug
2024-07-21 03:35:09 +02:00

79 lines
1.9 KiB
Go

package dav
import (
"fmt"
"html"
"path/filepath"
"strings"
)
// optimized versions, no more marshalling
func Directory(path, added string) string {
return fmt.Sprintf(`<d:response>
<d:href>%s</d:href>
<d:propstat>
<d:prop>
<d:resourcetype>
<d:collection/>
</d:resourcetype>
<d:getlastmodified>%s</d:getlastmodified>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>`, customPathEscape(path), added)
}
func File(path string, fileSize int64, added string) string {
return fmt.Sprintf(`<d:response>
<d:href>%s</d:href>
<d:propstat>
<d:prop>
<d:getcontentlength>%d</d:getcontentlength>
<d:getlastmodified>%s</d:getlastmodified>
<d:resourcetype></d:resourcetype>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>`, customPathEscape(path), fileSize, added)
}
func VidHubDirectory(path, added string) string {
if !strings.HasSuffix(path, "/") {
path += "/"
}
displayName := html.EscapeString(filepath.Base(path))
if displayName == "\\" {
displayName = "/"
}
return fmt.Sprintf(`<d:response>
<d:href>%s</d:href>
<d:propstat>
<d:prop>
<d:displayname>%s</d:displayname>
<d:resourcetype>
<d:collection/>
</d:resourcetype>
<d:getlastmodified>%s</d:getlastmodified>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>`, customPathEscape(path), displayName, added)
}
func VidHubFile(path string, fileSize int64, added string) string {
filename := filepath.Base(path)
return fmt.Sprintf(`<d:response>
<d:href>%s</d:href>
<d:propstat>
<d:prop>
<d:displayname>%s</d:displayname>
<d:getcontentlength>%d</d:getcontentlength>
<d:getlastmodified>%s</d:getlastmodified>
<d:resourcetype></d:resourcetype>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>`, customPathEscape(path), html.EscapeString(filename), fileSize, added)
}