filebrowser/backend/http/search.go

26 lines
638 B
Go
Raw Normal View History

package http
import (
2023-06-15 01:08:09 +00:00
"github.com/gtsteffaniak/filebrowser/search"
2023-08-12 16:30:41 +00:00
"net/http"
)
var searchHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
response := []map[string]interface{}{}
query := r.URL.Query().Get("query")
indexInfo, fileTypes := search.SearchAllIndexes(query, r.URL.Path)
2023-08-12 16:30:41 +00:00
for _, path := range indexInfo {
2023-07-13 02:23:29 +00:00
f := fileTypes[path]
responseObj := map[string]interface{}{
2023-08-12 16:30:41 +00:00
"path": path,
2023-07-13 02:23:29 +00:00
}
2023-08-12 16:30:41 +00:00
for filterType, _ := range f {
if f[filterType] {
responseObj[filterType] = f[filterType]
}
2023-07-13 02:23:29 +00:00
}
2023-08-12 16:30:41 +00:00
response = append(response, responseObj)
}
return renderJSON(w, r, response)
2023-08-12 16:30:41 +00:00
})