✨🚧 Implement admin interface to manage shares and users

This commit is contained in:
2020-10-24 16:57:00 +02:00
parent f798551b97
commit 5034d1a1f8
12 changed files with 503 additions and 2 deletions
+15 -2
View File
@@ -32,17 +32,20 @@ import (
"net/http"
"strings"
"github.com/go-chi/chi"
"golang.org/x/crypto/bcrypt"
"golang.org/x/net/webdav"
)
type CmdServe struct {
ListenAddress string `name:"listen-address" default:":3000" help:"Address to listen on for HTTP requests."`
WebDavPath string `name:"dav-path" default:"/dav" help:"Path to use for WebDAV requests."`
AdminPath string `name:"admin-path" default:"/admin" help:"Path to use for the admin interface."`
}
func (cmd *CmdServe) Run(app *app) error {
h := &webdav.Handler{}
h.Prefix = "/dav/"
h.Prefix = cmd.WebDavPath + "/"
h.LockSystem = webdav.NewMemLS()
h.FileSystem = BaseDir(app.DataDirectory)
@@ -95,8 +98,18 @@ func (cmd *CmdServe) Run(app *app) error {
h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), "mapping", &directoryMapping)))
})
r := chi.NewRouter()
r.Mount(cmd.AdminPath, newWebAdminHandler(app))
// Can't use Chi at the root, since it can't properly handle the mounted WebDAV
// handler. So we register Chi as the default handler, but delegate the WebDAV
// path with the default mux.
m := http.NewServeMux()
m.Handle("/", r)
m.Handle(h.Prefix, authenticatedWebdavHandler)
fmt.Printf("Listening on %s\n", cmd.ListenAddress)
if err := http.ListenAndServe(cmd.ListenAddress, authenticatedWebdavHandler); err != http.ErrServerClosed && err != nil {
if err := http.ListenAndServe(cmd.ListenAddress, m); err != http.ErrServerClosed && err != nil {
return fmt.Errorf("cannot listen: %w", err)
}
return nil