58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package dav
|
|
|
|
import (
|
|
"net/url"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
func customPathEscape(input string) string {
|
|
// First, URL-escape the path segments
|
|
segments := strings.Split(input, "/")
|
|
for i, segment := range segments {
|
|
escapedSegment := strings.ReplaceAll(segment, "%", "ZURG25")
|
|
escapedSegment = url.PathEscape(escapedSegment)
|
|
escapedSegment = strings.ReplaceAll(escapedSegment, "ZURG25", "%25")
|
|
segments[i] = escapedSegment
|
|
}
|
|
escapedPath := strings.Join(segments, "/")
|
|
return escapeForXML(escapedPath)
|
|
}
|
|
|
|
func escapeForXML(input string) string {
|
|
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
|
|
}
|
|
|
|
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"
|
|
}
|
|
}
|