fix some bugs and add stuff to config
This commit is contained in:
parent
8d0214f74a
commit
408fa2e86f
|
@ -70,7 +70,8 @@ func Parse(c *caddy.Controller) ([]Config, error) {
|
||||||
|
|
||||||
for c.Next() {
|
for c.Next() {
|
||||||
var cfg = Config{UserConfig: &UserConfig{}}
|
var cfg = Config{UserConfig: &UserConfig{}}
|
||||||
cfg.PathScope = "./"
|
cfg.PathScope = "."
|
||||||
|
cfg.Root = http.Dir(cfg.PathScope)
|
||||||
cfg.BaseURL = ""
|
cfg.BaseURL = ""
|
||||||
cfg.FrontMatter = "yaml"
|
cfg.FrontMatter = "yaml"
|
||||||
cfg.HugoEnabled = false
|
cfg.HugoEnabled = false
|
||||||
|
@ -235,8 +236,6 @@ func Parse(c *caddy.Controller) ([]Config, error) {
|
||||||
cfg.BaseURL = strings.TrimSuffix(cfg.BaseURL, "/")
|
cfg.BaseURL = strings.TrimSuffix(cfg.BaseURL, "/")
|
||||||
cfg.BaseURL = "/" + cfg.BaseURL
|
cfg.BaseURL = "/" + cfg.BaseURL
|
||||||
|
|
||||||
cfg.Root = http.Dir(cfg.PathScope)
|
|
||||||
|
|
||||||
caddyConf := httpserver.GetConfig(c)
|
caddyConf := httpserver.GetConfig(c)
|
||||||
cfg.AbsoluteURL = strings.TrimSuffix(caddyConf.Addr.Path, "/") + "/" + cfg.BaseURL
|
cfg.AbsoluteURL = strings.TrimSuffix(caddyConf.Addr.Path, "/") + "/" + cfg.BaseURL
|
||||||
cfg.AbsoluteURL = strings.Replace(cfg.AbsoluteURL, "//", "/", -1)
|
cfg.AbsoluteURL = strings.Replace(cfg.AbsoluteURL, "//", "/", -1)
|
||||||
|
|
|
@ -37,14 +37,14 @@ type Info struct {
|
||||||
|
|
||||||
// GetInfo gets the file information and, in case of error, returns the
|
// GetInfo gets the file information and, in case of error, returns the
|
||||||
// respective HTTP error code
|
// respective HTTP error code
|
||||||
func GetInfo(url *url.URL, c *config.Config) (*Info, int, error) {
|
func GetInfo(url *url.URL, c *config.Config, u *config.UserConfig) (*Info, int, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
rootPath := strings.Replace(url.Path, c.BaseURL, "", 1)
|
rootPath := strings.Replace(url.Path, c.BaseURL, "", 1)
|
||||||
rootPath = strings.TrimPrefix(rootPath, "/")
|
rootPath = strings.TrimPrefix(rootPath, "/")
|
||||||
rootPath = "/" + rootPath
|
rootPath = "/" + rootPath
|
||||||
|
|
||||||
relpath := c.PathScope + rootPath
|
relpath := u.PathScope + rootPath
|
||||||
relpath = strings.Replace(relpath, "\\", "/", -1)
|
relpath = strings.Replace(relpath, "\\", "/", -1)
|
||||||
relpath = filepath.Clean(relpath)
|
relpath = filepath.Clean(relpath)
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func GetInfo(url *url.URL, c *config.Config) (*Info, int, error) {
|
||||||
RootPath: rootPath,
|
RootPath: rootPath,
|
||||||
Path: relpath,
|
Path: relpath,
|
||||||
}
|
}
|
||||||
f, err := c.Root.Open(rootPath)
|
f, err := u.Root.Open(rootPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return file, errors.ToHTTPCode(err), err
|
return file, errors.ToHTTPCode(err), err
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ func (i *Info) serveSingleFile(w http.ResponseWriter, r *http.Request, c *config
|
||||||
func (i *Info) serveListing(w http.ResponseWriter, r *http.Request, c *config.Config, u *config.UserConfig) (int, error) {
|
func (i *Info) serveListing(w http.ResponseWriter, r *http.Request, c *config.Config, u *config.UserConfig) (int, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
file, err := c.Root.Open(i.RootPath)
|
file, err := u.Root.Open(i.RootPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.ToHTTPCode(err), err
|
return errors.ToHTTPCode(err), err
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Method != http.MethodPost && !serveAssets {
|
if r.Method != http.MethodPost && !serveAssets {
|
||||||
fi, code, err = directory.GetInfo(r.URL, c)
|
fi, code, err = directory.GetInfo(r.URL, c, user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if r.Method == http.MethodGet {
|
if r.Method == http.MethodGet {
|
||||||
return errors.PrintHTML(w, code, err)
|
return errors.PrintHTML(w, code, err)
|
||||||
|
|
Loading…
Reference in New Issue