filebrowser/backend/http/search.go

25 lines
638 B
Go
Raw Normal View History

package http
import (
"net/http"
2023-06-15 01:08:09 +00:00
"github.com/gtsteffaniak/filebrowser/search"
)
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)
for _,path := range(indexInfo){
2023-07-13 02:23:29 +00:00
f := fileTypes[path]
responseObj := map[string]interface{}{
"path" : path,
}
for filterType,_ := range(f) {
if f[filterType] {
responseObj[filterType] = f[filterType]
}
2023-07-13 02:23:29 +00:00
}
response = append(response,responseObj)
}
return renderJSON(w, r, response)
2023-06-18 15:04:31 +00:00
})