Implement vidhub handlers
This commit is contained in:
@@ -3,12 +3,13 @@ package dav
|
||||
import (
|
||||
"fmt"
|
||||
"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)
|
||||
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 {
|
||||
@@ -16,7 +17,22 @@ 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 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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -23,3 +23,13 @@ func customPathEscape(input string) string {
|
||||
escapedPath = strings.ReplaceAll(escapedPath, "@", "%40")
|
||||
return escapedPath
|
||||
}
|
||||
|
||||
func customPathEscape2(input string) string {
|
||||
// Convert any XML-escaped sequences back to URL-escaped sequences
|
||||
input = strings.ReplaceAll(input, "$", "%24")
|
||||
input = strings.ReplaceAll(input, "&", "%26")
|
||||
input = strings.ReplaceAll(input, "+", "%2B")
|
||||
input = strings.ReplaceAll(input, ":", "%3A")
|
||||
input = strings.ReplaceAll(input, "@", "%40")
|
||||
return input
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user