Skip to content

Commit

Permalink
Merge pull request #174 from krypty/add-option-to-disable-index
Browse files Browse the repository at this point in the history
Add no-index option to disable indexing and search
  • Loading branch information
codeskyblue committed Dec 19, 2023
2 parents 5fab10e + 88433ea commit f2fb06a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 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 @@ -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 = "./"
// }
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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{}
Expand Down Expand Up @@ -98,6 +99,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())
Expand All @@ -119,6 +121,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

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

Please sign in to comment.