Add VidHub endpoints
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user