diff --git a/httpstaticserver.go b/httpstaticserver.go index b26ffe4..694ef59 100644 --- a/httpstaticserver.go +++ b/httpstaticserver.go @@ -48,16 +48,17 @@ type Directory struct { } type HTTPStaticServer struct { - Root string - Prefix string - Upload bool - Delete bool - Title string - Theme string - PlistProxy string - GoogleTrackerID string - AuthType string - NoIndex bool + Root string + Prefix string + Upload bool + Delete bool + Title string + Theme string + PlistProxy string + GoogleTrackerID string + AuthType string + DeepPathMaxDepth int + NoIndex bool indexes []IndexFileItem m *mux.Router @@ -575,6 +576,7 @@ func (s *HTTPStaticServer) hJSONList(w http.ResponseWriter, r *http.Request) { auth := s.readAccessConf(realPath) auth.Upload = auth.canUpload(r) auth.Delete = auth.canDelete(r) + maxDepth := s.DeepPathMaxDepth // path string -> info os.FileInfo fileInfoMap := make(map[string]os.FileInfo, 0) @@ -619,7 +621,7 @@ func (s *HTTPStaticServer) hJSONList(w http.ResponseWriter, r *http.Request) { lr.Name = filepath.ToSlash(name) // fix for windows } if info.IsDir() { - name := deepPath(realPath, info.Name()) + name := deepPath(realPath, info.Name(), maxDepth) lr.Name = name lr.Path = filepath.Join(filepath.Dir(path), name) lr.Type = "dir" @@ -744,9 +746,8 @@ func (s *HTTPStaticServer) readAccessConf(realPath string) (ac AccessConf) { return } -func deepPath(basedir, name string) string { +func deepPath(basedir, name string, maxDepth int) string { // loop max 5, incase of for loop not finished - maxDepth := 5 for depth := 0; depth <= maxDepth; depth += 1 { finfos, err := ioutil.ReadDir(filepath.Join(basedir, name)) if err != nil || len(finfos) != 1 { diff --git a/main.go b/main.go index ce04058..c78f96e 100644 --- a/main.go +++ b/main.go @@ -48,7 +48,8 @@ type Configure struct { ID string `yaml:"id"` // for oauth2 Secret string `yaml:"secret"` // for oauth2 } `yaml:"auth"` - NoIndex bool `yaml:"no-index"` + DeepPathMaxDepth int `yaml:"deep-path-max-depth"` + NoIndex bool `yaml:"no-index"` } type httpLogger struct{} @@ -99,6 +100,7 @@ func parseFlags() error { gcfg.Auth.OpenID = defaultOpenID gcfg.GoogleTrackerID = "UA-81205425-2" gcfg.Title = "Go HTTP File Server" + gcfg.DeepPathMaxDepth = 5 gcfg.NoIndex = false kingpin.HelpFlag.Short('h') @@ -121,6 +123,7 @@ func parseFlags() error { kingpin.Flag("plistproxy", "plist proxy when server is not https").Short('p').StringVar(&gcfg.PlistProxy) kingpin.Flag("title", "server title").StringVar(&gcfg.Title) kingpin.Flag("google-tracker-id", "set to empty to disable it").StringVar(&gcfg.GoogleTrackerID) + kingpin.Flag("deep-path-max-depth", "set to -1 to not combine dirs").IntVar(&gcfg.DeepPathMaxDepth) kingpin.Flag("no-index", "disable indexing").BoolVar(&gcfg.NoIndex) kingpin.Parse() // first parse conf @@ -186,6 +189,7 @@ func main() { ss.Upload = gcfg.Upload ss.Delete = gcfg.Delete ss.AuthType = gcfg.Auth.Type + ss.DeepPathMaxDepth = gcfg.DeepPathMaxDepth if gcfg.PlistProxy != "" { u, err := url.Parse(gcfg.PlistProxy)