Add VidHub endpoints

This commit is contained in:
Ben Adrian Sarmiento
2024-07-11 15:53:20 +02:00
parent f8f68e8225
commit 396a8781aa
10 changed files with 182 additions and 86 deletions

View File

@@ -2,37 +2,74 @@ package dav
import (
"fmt"
"html"
"path/filepath"
"strings"
)
// optimized versions, no more marshalling
func BaseDirectory(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 Directory(path, added string) string {
path = filepath.Base(path)
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 BaseFile(path string, fileSize int64, added string) string {
return fmt.Sprintf("<d:response><d:href>%s</d:href><d:propstat><d:prop><d:resourcetype></d:resourcetype><d:getcontentlength>%d</d:getcontentlength><d:getlastmodified>%s</d:getlastmodified></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response>", customPathEscape(path), fileSize, added)
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 {
path = filepath.Base(path)
return fmt.Sprintf("<d:response><d:href>%s</d:href><d:propstat><d:prop><d:resourcetype></d:resourcetype><d:getcontentlength>%d</d:getcontentlength><d:getlastmodified>%s</d:getlastmodified></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response>", customPathEscape(path), fileSize, added)
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: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>", customPathEscape2(path), added)
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 {
return fmt.Sprintf("<d:response><d:href>%s</d:href><d:propstat><d:prop><d:resourcetype></d:resourcetype><d:getcontentlength>%d</d:getcontentlength><d:getlastmodified>%s</d:getlastmodified></d:prop><d:status>HTTP/1.1 200 OK</d:status></d:propstat></d:response>", customPathEscape2(path), fileSize, added)
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))
}