2019-01-05 22:44:33 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2023-06-15 01:08:09 +00:00
|
|
|
"github.com/gtsteffaniak/filebrowser/search"
|
2019-01-05 22:44:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var searchHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
|
|
|
response := []map[string]interface{}{}
|
|
|
|
query := r.URL.Query().Get("query")
|
2023-07-17 05:17:52 +00:00
|
|
|
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,
|
|
|
|
}
|
2023-07-17 05:17:52 +00:00
|
|
|
for filterType,_ := range(f) {
|
|
|
|
if f[filterType] {
|
|
|
|
responseObj[filterType] = f[filterType]
|
|
|
|
}
|
2023-07-13 02:23:29 +00:00
|
|
|
}
|
|
|
|
response = append(response,responseObj)
|
2023-06-15 15:30:49 +00:00
|
|
|
}
|
2019-01-05 22:44:33 +00:00
|
|
|
return renderJSON(w, r, response)
|
2023-06-18 15:04:31 +00:00
|
|
|
})
|