Working Caddy
parent
c6e6b08305
commit
e4d345b7e5
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -345,6 +345,7 @@ var DefaultUser = User{
|
|||
CSS: "",
|
||||
Admin: true,
|
||||
Locale: "en",
|
||||
Scope: ".",
|
||||
FileSystem: fileutils.Dir("."),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue