filebrowser/backend/http/search.go

30 lines
710 B
Go
Raw Normal View History

package http
import (
2023-08-12 16:30:41 +00:00
"net/http"
2023-08-12 22:21:31 +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)
2023-08-12 16:30:41 +00:00
for _, path := range indexInfo {
2023-07-13 02:23:29 +00:00
responseObj := map[string]interface{}{
2023-08-12 16:30:41 +00:00
"path": path,
2023-08-12 22:21:31 +00:00
"dir": true,
2023-07-13 02:23:29 +00:00
}
2023-08-12 22:21:31 +00:00
if _, ok := fileTypes[path]; ok {
responseObj["dir"] = false
for filterType, value := range fileTypes[path] {
if value {
responseObj[filterType] = value
}
}
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
})