From e4d345b7e59b6d895220a6cfec939f528fad5db5 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 20 Aug 2017 09:31:24 +0100 Subject: [PATCH] Working Caddy --- caddy/filemanager/filemanager.go | 3 ++- caddy/hugo/hugo.go | 3 ++- caddy/jekyll/jekyll.go | 3 ++- caddy/parser/parser.go | 36 ++++++++++++++++++++++++++------ cmd/filemanager/main.go | 4 ++-- filemanager.go | 1 + 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/caddy/filemanager/filemanager.go b/caddy/filemanager/filemanager.go index 98ae6812..979854cc 100644 --- a/caddy/filemanager/filemanager.go +++ b/caddy/filemanager/filemanager.go @@ -8,6 +8,7 @@ import ( "github.com/hacdias/filemanager" "github.com/hacdias/filemanager/caddy/parser" + h "github.com/hacdias/filemanager/http" "github.com/mholt/caddy" "github.com/mholt/caddy/caddyhttp/httpserver" ) @@ -32,7 +33,7 @@ func (f plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { continue } - f.Configs[i].ServeHTTP(w, r) + h.Handler(f.Configs[i]).ServeHTTP(w, r) return 0, nil } diff --git a/caddy/hugo/hugo.go b/caddy/hugo/hugo.go index f1a6cdbf..dedb24ce 100644 --- a/caddy/hugo/hugo.go +++ b/caddy/hugo/hugo.go @@ -5,6 +5,7 @@ import ( "github.com/hacdias/filemanager" "github.com/hacdias/filemanager/caddy/parser" + h "github.com/hacdias/filemanager/http" "github.com/mholt/caddy" "github.com/mholt/caddy/caddyhttp/httpserver" ) @@ -29,7 +30,7 @@ func (f plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { continue } - f.Configs[i].ServeHTTP(w, r) + h.Handler(f.Configs[i]).ServeHTTP(w, r) return 0, nil } diff --git a/caddy/jekyll/jekyll.go b/caddy/jekyll/jekyll.go index d2ffa964..b41d4f5e 100644 --- a/caddy/jekyll/jekyll.go +++ b/caddy/jekyll/jekyll.go @@ -5,6 +5,7 @@ import ( "github.com/hacdias/filemanager" "github.com/hacdias/filemanager/caddy/parser" + h "github.com/hacdias/filemanager/http" "github.com/mholt/caddy" "github.com/mholt/caddy/caddyhttp/httpserver" ) @@ -29,7 +30,7 @@ func (f plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { continue } - f.Configs[i].ServeHTTP(w, r) + h.Handler(f.Configs[i]).ServeHTTP(w, r) return 0, nil } diff --git a/caddy/parser/parser.go b/caddy/parser/parser.go index 33a886e3..1f531136 100644 --- a/caddy/parser/parser.go +++ b/caddy/parser/parser.go @@ -10,10 +10,14 @@ import ( "strconv" "strings" + "github.com/asdine/storm" "github.com/hacdias/filemanager" + "github.com/hacdias/filemanager/bolt" + "github.com/hacdias/filemanager/staticgen" "github.com/hacdias/fileutils" "github.com/mholt/caddy" "github.com/mholt/caddy/caddyhttp/httpserver" + "github.com/spf13/viper" ) // Parse ... @@ -24,7 +28,7 @@ func Parse(c *caddy.Controller, plugin string) ([]*filemanager.FileManager, erro ) for c.Next() { - u := filemanager.User{ + u := &filemanager.User{ Locale: "en", AllowCommands: true, AllowEdit: true, @@ -183,13 +187,33 @@ func Parse(c *caddy.Controller, plugin string) ([]*filemanager.FileManager, erro ". It is highly recommended that you set the 'database' option to '" + sha + ".db'\n") } + u.Scope = scope u.FileSystem = fileutils.Dir(scope) - m, err := filemanager.New(database, u) + + db, err := storm.Open(database) + if err != nil { + return nil, err + } + + m := &filemanager.FileManager{ + NoAuth: viper.GetBool("NoAuth"), + BaseURL: "", + PrefixURL: "", + DefaultUser: u, + Store: &filemanager.Store{ + Config: bolt.ConfigStore{DB: db}, + Users: bolt.UsersStore{DB: db}, + Share: bolt.ShareStore{DB: db}, + }, + NewFS: func(scope string) filemanager.FileSystem { + return fileutils.Dir(scope) + }, + } switch plugin { case "hugo": // Initialize the default settings for Hugo. - hugo := &filemanager.Hugo{ + hugo := &staticgen.Hugo{ Root: scope, Public: filepath.Join(scope, "public"), Args: []string{}, @@ -197,13 +221,13 @@ func Parse(c *caddy.Controller, plugin string) ([]*filemanager.FileManager, erro } // Attaches Hugo plugin to this file manager instance. - err = m.EnableStaticGen(hugo) + err = m.Attach(hugo) if err != nil { return nil, err } case "jekyll": // Initialize the default settings for Jekyll. - jekyll := &filemanager.Jekyll{ + jekyll := &staticgen.Jekyll{ Root: scope, Public: filepath.Join(scope, "_site"), Args: []string{}, @@ -211,7 +235,7 @@ func Parse(c *caddy.Controller, plugin string) ([]*filemanager.FileManager, erro } // Attaches Hugo plugin to this file manager instance. - err = m.EnableStaticGen(jekyll) + err = m.Attach(jekyll) if err != nil { return nil, err } diff --git a/cmd/filemanager/main.go b/cmd/filemanager/main.go index bce11788..7a358299 100644 --- a/cmd/filemanager/main.go +++ b/cmd/filemanager/main.go @@ -201,7 +201,7 @@ func handler() http.Handler { }, } - err = fm.Load() + err = fm.Setup() if err != nil { log.Fatal(err) } @@ -231,5 +231,5 @@ func handler() http.Handler { } } - return h.ServeHTTP(fm) + return h.Handler(fm) } diff --git a/filemanager.go b/filemanager.go index 87f398aa..5af085cf 100644 --- a/filemanager.go +++ b/filemanager.go @@ -345,6 +345,7 @@ var DefaultUser = User{ CSS: "", Admin: true, Locale: "en", + Scope: ".", FileSystem: fileutils.Dir("."), }