Skip to content

Commit 75eb27f

Browse files
committed
merge pr
2 parents a400a02 + e31775a commit 75eb27f

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

httpstaticserver.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ type Directory struct {
4848
}
4949

5050
type HTTPStaticServer struct {
51-
Root string
52-
Prefix string
53-
Upload bool
54-
Delete bool
55-
Title string
56-
Theme string
57-
PlistProxy string
58-
GoogleTrackerID string
59-
AuthType string
60-
NoIndex bool
51+
Root string
52+
Prefix string
53+
Upload bool
54+
Delete bool
55+
Title string
56+
Theme string
57+
PlistProxy string
58+
GoogleTrackerID string
59+
AuthType string
60+
DeepPathMaxDepth int
61+
NoIndex bool
6162

6263
indexes []IndexFileItem
6364
m *mux.Router
@@ -575,6 +576,7 @@ func (s *HTTPStaticServer) hJSONList(w http.ResponseWriter, r *http.Request) {
575576
auth := s.readAccessConf(realPath)
576577
auth.Upload = auth.canUpload(r)
577578
auth.Delete = auth.canDelete(r)
579+
maxDepth := s.DeepPathMaxDepth
578580

579581
// path string -> info os.FileInfo
580582
fileInfoMap := make(map[string]os.FileInfo, 0)
@@ -619,7 +621,7 @@ func (s *HTTPStaticServer) hJSONList(w http.ResponseWriter, r *http.Request) {
619621
lr.Name = filepath.ToSlash(name) // fix for windows
620622
}
621623
if info.IsDir() {
622-
name := deepPath(realPath, info.Name())
624+
name := deepPath(realPath, info.Name(), maxDepth)
623625
lr.Name = name
624626
lr.Path = filepath.Join(filepath.Dir(path), name)
625627
lr.Type = "dir"
@@ -744,9 +746,8 @@ func (s *HTTPStaticServer) readAccessConf(realPath string) (ac AccessConf) {
744746
return
745747
}
746748

747-
func deepPath(basedir, name string) string {
749+
func deepPath(basedir, name string, maxDepth int) string {
748750
// loop max 5, incase of for loop not finished
749-
maxDepth := 5
750751
for depth := 0; depth <= maxDepth; depth += 1 {
751752
finfos, err := ioutil.ReadDir(filepath.Join(basedir, name))
752753
if err != nil || len(finfos) != 1 {

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ type Configure struct {
4848
ID string `yaml:"id"` // for oauth2
4949
Secret string `yaml:"secret"` // for oauth2
5050
} `yaml:"auth"`
51-
NoIndex bool `yaml:"no-index"`
51+
DeepPathMaxDepth int `yaml:"deep-path-max-depth"`
52+
NoIndex bool `yaml:"no-index"`
5253
}
5354

5455
type httpLogger struct{}
@@ -99,6 +100,7 @@ func parseFlags() error {
99100
gcfg.Auth.OpenID = defaultOpenID
100101
gcfg.GoogleTrackerID = "UA-81205425-2"
101102
gcfg.Title = "Go HTTP File Server"
103+
gcfg.DeepPathMaxDepth = 5
102104
gcfg.NoIndex = false
103105

104106
kingpin.HelpFlag.Short('h')
@@ -121,6 +123,7 @@ func parseFlags() error {
121123
kingpin.Flag("plistproxy", "plist proxy when server is not https").Short('p').StringVar(&gcfg.PlistProxy)
122124
kingpin.Flag("title", "server title").StringVar(&gcfg.Title)
123125
kingpin.Flag("google-tracker-id", "set to empty to disable it").StringVar(&gcfg.GoogleTrackerID)
126+
kingpin.Flag("deep-path-max-depth", "set to -1 to not combine dirs").IntVar(&gcfg.DeepPathMaxDepth)
124127
kingpin.Flag("no-index", "disable indexing").BoolVar(&gcfg.NoIndex)
125128

126129
kingpin.Parse() // first parse conf
@@ -186,6 +189,7 @@ func main() {
186189
ss.Upload = gcfg.Upload
187190
ss.Delete = gcfg.Delete
188191
ss.AuthType = gcfg.Auth.Type
192+
ss.DeepPathMaxDepth = gcfg.DeepPathMaxDepth
189193

190194
if gcfg.PlistProxy != "" {
191195
u, err := url.Parse(gcfg.PlistProxy)

0 commit comments

Comments
 (0)