filebrowser/src/backend/http/search.go

30 lines
789 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")
2023-07-13 02:23:29 +00:00
files, dirs, fileTypes := search.SearchAllIndexes(query, r.URL.Path)
for _,path := range(files){
f := fileTypes[path]
responseObj := map[string]interface{}{
"dir" : false,
"path" : path,
}
for _,filterType := range(search.FilterableTypes) {
if f[filterType] { responseObj[filterType] = f[filterType] }
}
response = append(response,responseObj)
}
for _,v := range(dirs){
response = append(response, map[string]interface{}{
"dir": true,
"path": v,
})
}
return renderJSON(w, r, response)
2023-06-18 15:04:31 +00:00
})