✨ Use a dedicated path for the shares
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/go-chi/chi"
|
||||
pwgen "github.com/sethvargo/go-password/password"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"golang.org/x/net/webdav"
|
||||
@@ -73,6 +74,7 @@ func main() {
|
||||
c := LoadConfig(*configFile)
|
||||
|
||||
h := &webdav.Handler{}
|
||||
h.Prefix = "/share/"
|
||||
h.LockSystem = webdav.NewMemLS()
|
||||
h.FileSystem = BaseDir(c.BaseDirectory)
|
||||
|
||||
@@ -88,11 +90,20 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
shareName := chi.URLParam(r, "share")
|
||||
directoryMapping := DirectoryMapping{
|
||||
VirtualName: shareName,
|
||||
RealName: directory,
|
||||
}
|
||||
|
||||
// Use the WebDAV handler to actually serve the request. Also enhance the context
|
||||
// to contain the subdirectory (of the base directory) which contains the data for
|
||||
// the authenticated user.
|
||||
h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), "dir", directory)))
|
||||
h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), "mapping", &directoryMapping)))
|
||||
})
|
||||
|
||||
http.ListenAndServe(c.ListenAddress, authenticatedWebdavHandler)
|
||||
r := chi.NewRouter()
|
||||
r.Handle("/share/{share}/*", authenticatedWebdavHandler)
|
||||
|
||||
http.ListenAndServe(c.ListenAddress, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user