Files
zurg/pkg/dav/response.go
Ben Adrian Sarmiento 396a8781aa Add VidHub endpoints
2024-07-11 15:53:20 +02:00

76 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 += "/"
}
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), html.EscapeString(filepath.Base(path)), 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:getcontenttype>%s</d:getcontenttype>
<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, getContentType(filename))
}