From 88433ea55e2d7bf37fd9c4b0b8b02530bdd6c80a Mon Sep 17 00:00:00 2001 From: Gary Marigliano Date: Mon, 13 Mar 2023 08:59:20 +0100 Subject: [PATCH] Add no-index option to disable indexing and search --- assets/index.html | 3 +++ httpstaticserver.go | 30 +++++++++++++++++------------- main.go | 5 ++++- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/assets/index.html b/assets/index.html index e22220b..2dc0e88 100644 --- a/assets/index.html +++ b/assets/index.html @@ -64,6 +64,8 @@ [[end]] + + [[if not .NoIndex ]] + [[end]] diff --git a/httpstaticserver.go b/httpstaticserver.go index c5ddf9e..b26ffe4 100644 --- a/httpstaticserver.go +++ b/httpstaticserver.go @@ -57,13 +57,14 @@ type HTTPStaticServer struct { PlistProxy string GoogleTrackerID string AuthType string + NoIndex bool indexes []IndexFileItem m *mux.Router bufPool sync.Pool // use sync.Pool caching buf to reduce gc ratio } -func NewHTTPStaticServer(root string) *HTTPStaticServer { +func NewHTTPStaticServer(root string, noIndex bool) *HTTPStaticServer { // if root == "" { // root = "./" // } @@ -81,20 +82,23 @@ func NewHTTPStaticServer(root string) *HTTPStaticServer { bufPool: sync.Pool{ New: func() interface{} { return make([]byte, 32*1024) }, }, + NoIndex: noIndex, + } + + if !noIndex { + go func() { + time.Sleep(1 * time.Second) + for { + startTime := time.Now() + log.Println("Started making search index") + s.makeIndex() + log.Printf("Completed search index in %v", time.Since(startTime)) + //time.Sleep(time.Second * 1) + time.Sleep(time.Minute * 10) + } + }() } - go func() { - time.Sleep(1 * time.Second) - for { - startTime := time.Now() - log.Println("Started making search index") - s.makeIndex() - log.Printf("Completed search index in %v", time.Since(startTime)) - //time.Sleep(time.Second * 1) - time.Sleep(time.Minute * 10) - } - }() - // routers for Apple *.ipa m.HandleFunc("/-/ipa/plist/{path:.*}", s.hPlist) m.HandleFunc("/-/ipa/link/{path:.*}", s.hIpaLink) diff --git a/main.go b/main.go index 0b5aea4..8474a21 100644 --- a/main.go +++ b/main.go @@ -49,6 +49,7 @@ type Configure struct { ID string `yaml:"id"` // for oauth2 Secret string `yaml:"secret"` // for oauth2 } `yaml:"auth"` + 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.NoIndex = false kingpin.HelpFlag.Short('h') kingpin.Version(versionMessage()) @@ -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("no-index", "disable indexing").BoolVar(&gcfg.NoIndex) kingpin.Parse() // first parse conf @@ -164,7 +167,7 @@ func main() { log.Printf("url prefix: %s", gcfg.Prefix) } - ss := NewHTTPStaticServer(gcfg.Root) + ss := NewHTTPStaticServer(gcfg.Root, gcfg.NoIndex) ss.Prefix = gcfg.Prefix ss.Theme = gcfg.Theme ss.Title = gcfg.Title