- Fix url escape for webdav files
- Add support for bind address, url base
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package webdav
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
@@ -14,7 +15,8 @@ type FileInfo struct {
|
||||
isDir bool
|
||||
}
|
||||
|
||||
func (fi *FileInfo) Name() string { return fi.name }
|
||||
func (fi *FileInfo) Name() string { return url.PathEscape(fi.name) }
|
||||
func (fi *FileInfo) RawName() string { return fi.name }
|
||||
func (fi *FileInfo) Size() int64 { return fi.size }
|
||||
func (fi *FileInfo) Mode() os.FileMode { return fi.mode }
|
||||
func (fi *FileInfo) ModTime() time.Time { return fi.modTime }
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
path "path/filepath"
|
||||
"slices"
|
||||
@@ -466,13 +465,6 @@ func (h *Handler) serveDirectory(w http.ResponseWriter, r *http.Request, file we
|
||||
"add": func(a, b int) int {
|
||||
return a + b
|
||||
},
|
||||
"urlpath": func(p string) string {
|
||||
segments := strings.Split(p, "/")
|
||||
for i, segment := range segments {
|
||||
segments[i] = url.PathEscape(segment)
|
||||
}
|
||||
return strings.Join(segments, "/")
|
||||
},
|
||||
"formatSize": func(bytes int64) string {
|
||||
const (
|
||||
KB = 1024
|
||||
|
||||
@@ -109,13 +109,13 @@ const directoryTemplate = `
|
||||
<h1>Index of {{.Path}}</h1>
|
||||
<ul>
|
||||
{{if .ShowParent}}
|
||||
<li><a href="{{urlpath .ParentPath}}" class="parent-dir"><span class="file-number"></span>Parent Directory</a></li>
|
||||
<li><a href="{{ .ParentPath}}" class="parent-dir"><span class="file-number"></span>Parent Directory</a></li>
|
||||
{{end}}
|
||||
{{range $index, $file := .Children}}
|
||||
<li>
|
||||
<a href="{{urlpath (printf "%s/%s" $.Path $file.Name)}}">
|
||||
<a href="{{(printf "%s/%s" $.Path $file.Name)}}">
|
||||
<span class="file-number">{{add $index 1}}.</span>
|
||||
<span class="file-name">{{$file.Name}}{{if $file.IsDir}}/{{end}}</span>
|
||||
<span class="file-name">{{$file.RawName}}{{if $file.IsDir}}/{{end}}</span>
|
||||
<span class="file-info">
|
||||
{{if not $file.IsDir}}
|
||||
{{formatSize $file.Size}}
|
||||
|
||||
Reference in New Issue
Block a user