Skip to content

Commit

Permalink
Add no-index option to disable indexing and search
Browse files Browse the repository at this point in the history
  • Loading branch information
krypty authored and codeskyblue committed Dec 19, 2023
1 parent dbd0e06 commit 2a0e1f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
3 changes: 3 additions & 0 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
</template>
[[end]]
</ul>

[[if not .NoIndex ]]
<form class="navbar-form navbar-right">
<div class="input-group">
<input type="text" name="search" class="form-control" placeholder="Search text" v-bind:value="search"
Expand All @@ -75,6 +77,7 @@
</span>
</div>
</form>
[[end]]
<ul id="nav-right-bar" class="nav navbar-nav navbar-right">
</ul>
</div>
Expand Down
30 changes: 17 additions & 13 deletions httpstaticserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ type HTTPStaticServer struct {
GoogleTrackerID string
AuthType string
DeepPathMaxDepth int
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 = "./"
// }
Expand All @@ -82,20 +83,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)
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type Configure struct {
ID string `yaml:"id"` // for oauth2
Secret string `yaml:"secret"` // for oauth2
} `yaml:"auth"`
DeepPathMaxDepth int `yaml:"deep-path-max-depth"`
DeepPathMaxDepth int `yaml:"deep-path-max-depth"`
NoIndex bool `yaml:"no-index"`
}

type httpLogger struct{}
Expand Down Expand Up @@ -100,6 +101,7 @@ func parseFlags() error {
gcfg.GoogleTrackerID = "UA-81205425-2"
gcfg.Title = "Go HTTP File Server"
gcfg.DeepPathMaxDepth = 5
gcfg.NoIndex = false

kingpin.HelpFlag.Short('h')
kingpin.Version(versionMessage())
Expand All @@ -122,6 +124,7 @@ func parseFlags() error {
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

Expand Down Expand Up @@ -178,7 +181,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
Expand Down

0 comments on commit 2a0e1f7

Please sign in to comment.