Skip to content

Commit

Permalink
add --disable-global-search
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Sep 7, 2020
1 parent 96a0e4e commit c274f8e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Use these to configure your Andesite instance. All are optional. "Name" refers t
| `--hash-concurrency` | | `int` | cpu count | Number of hashes to run concurrently. |
| `--custom-root-public` | | `string[]` | none | Similar to `"roots_public"`, passed in the form `name=path`. |
| `--custom-root-private` | | `string[]` | none | Similar to `"roots_private"`, passed in the form `name=path`. |
| `--disable-global-search` | `bool` | `false` | When true, `/search` requires being an admin to use. |

> Note: for `--enable-search` and `--disable-search`, sending values to these flags will trigger a background scan of the root directory you point it at (whether that be `public`, `files`, etc). As such, unless content is changed or updated, it is not necessary to pass these flags across multiple runs of the app.
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"runtime"
"strings"

"github.com/nektro/andesite/pkg/config"
"github.com/nektro/andesite/pkg/db"
"github.com/nektro/andesite/pkg/fsdb"
"github.com/nektro/andesite/pkg/handler"
Expand Down Expand Up @@ -47,6 +48,7 @@ func main() {
vflag.IntVar(&idata.Config.HashPllel, "hash-concurrency", runtime.NumCPU(), "")
vflag.StringArrayVar(&idata.Config.CRootsPub, "custom-root-public", []string{}, "")
vflag.StringArrayVar(&idata.Config.CRootsPrv, "custom-root-private", []string{}, "")
vflag.BoolVar(&config.GlobalSearchOff, "disable-global-search", false, "")
etc.PreInit()

etc.Init(&idata.Config, "./files/", db.SaveOAuth2InfoCb)
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package config

var (
GlobalSearchOff bool
)
5 changes: 3 additions & 2 deletions pkg/handler/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"
"strings"

"github.com/nektro/andesite/pkg/config"
"github.com/nektro/andesite/pkg/db"
"github.com/nektro/andesite/pkg/idata"

Expand All @@ -12,7 +13,7 @@ import (
)

func HandleSearch(w http.ResponseWriter, r *http.Request) {
_, user, err := ApiBootstrap(r, w, []string{http.MethodGet}, false, false, true)
_, user, err := ApiBootstrap(r, w, []string{http.MethodGet}, config.GlobalSearchOff, config.GlobalSearchOff, true)
if err != nil {
return
}
Expand All @@ -25,7 +26,7 @@ func HandleSearch(w http.ResponseWriter, r *http.Request) {
}

func HandleSearchAPI(w http.ResponseWriter, r *http.Request) {
_, user, err := ApiBootstrap(r, w, []string{http.MethodGet}, false, false, false)
_, user, err := ApiBootstrap(r, w, []string{http.MethodGet}, config.GlobalSearchOff, config.GlobalSearchOff, false)
if err != nil {
WriteJSON(w, map[string]interface{}{
"response": "bad",
Expand Down

0 comments on commit c274f8e

Please sign in to comment.