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,6 +2,7 @@ package dav
import (
"net/url"
"path/filepath"
"strings"
)
@@ -15,17 +16,10 @@ func customPathEscape(input string) string {
segments[i] = escapedSegment
}
escapedPath := strings.Join(segments, "/")
// Convert any XML-escaped sequences back to URL-escaped sequences
escapedPath = strings.ReplaceAll(escapedPath, "$", "%24")
escapedPath = strings.ReplaceAll(escapedPath, "&", "%26")
escapedPath = strings.ReplaceAll(escapedPath, "+", "%2B")
escapedPath = strings.ReplaceAll(escapedPath, ":", "%3A")
escapedPath = strings.ReplaceAll(escapedPath, "@", "%40")
return escapedPath
return escapeForXML(escapedPath)
}
func customPathEscape2(input string) string {
// Convert any XML-escaped sequences back to URL-escaped sequences
func escapeForXML(input string) string {
input = strings.ReplaceAll(input, "$", "%24")
input = strings.ReplaceAll(input, "&", "%26")
input = strings.ReplaceAll(input, "+", "%2B")
@@ -33,3 +27,31 @@ func customPathEscape2(input string) string {
input = strings.ReplaceAll(input, "@", "%40")
return input
}
func getContentType(filename string) string {
filename = strings.ToLower(filename)
switch filepath.Ext(filename) {
case ".avi":
return "video/x-msvideo"
case ".m2ts":
return "video/mp2t"
case ".m4v":
return "video/x-m4v"
case ".mkv":
return "video/x-matroska"
case ".mov":
return "video/quicktime"
case ".mp4":
return "video/mp4"
case ".mpg":
return "video/mpeg"
case ".mpeg":
return "video/mpeg"
case ".ts":
return "video/mp2t"
case ".wmv":
return "video/x-ms-wmv"
default:
return "application/octet-stream"
}
}