✨ Implement WebDAV server
This commit is contained in:
+3
-10
@@ -44,8 +44,7 @@ import (
|
||||
)
|
||||
|
||||
type DirectoryMapping struct {
|
||||
VirtualName string
|
||||
RealName string
|
||||
DataDirName string
|
||||
}
|
||||
|
||||
// slashClean is equivalent to but slightly more efficient than
|
||||
@@ -61,23 +60,17 @@ type BaseDir string
|
||||
|
||||
func (d BaseDir) resolve(ctx context.Context, name string) string {
|
||||
directoryMapping := ctx.Value("mapping").(*DirectoryMapping)
|
||||
prefix := directoryMapping.VirtualName + "/"
|
||||
if !strings.HasPrefix(name, prefix) {
|
||||
// something does not add up
|
||||
return ""
|
||||
}
|
||||
nameWithoutPrefix := strings.TrimPrefix(name, prefix)
|
||||
|
||||
// This implementation is based on Dir.Open's code in the standard net/http package.
|
||||
if filepath.Separator != '/' && strings.IndexRune(name, filepath.Separator) >= 0 ||
|
||||
strings.Contains(nameWithoutPrefix, "\x00") {
|
||||
strings.Contains(name, "\x00") {
|
||||
return ""
|
||||
}
|
||||
dir := string(d)
|
||||
if dir == "" {
|
||||
dir = "."
|
||||
}
|
||||
return filepath.Join(dir, directoryMapping.RealName, filepath.FromSlash(slashClean(nameWithoutPrefix)))
|
||||
return filepath.Join(dir, directoryMapping.DataDirName, filepath.FromSlash(slashClean(name)))
|
||||
}
|
||||
|
||||
func (d BaseDir) Mkdir(ctx context.Context, name string, perm os.FileMode) error {
|
||||
|
||||
Reference in New Issue
Block a user