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-06-16 17:29:43 +00:00
|
|
|
var files []string
|
|
|
|
var dirs []string
|
|
|
|
files, dirs = search.IndexedSearch(query,r.URL.Path,&files,&dirs)
|
2023-06-15 15:30:49 +00:00
|
|
|
for _,v := range(files){
|
2019-01-05 22:44:33 +00:00
|
|
|
response = append(response, map[string]interface{}{
|
2023-06-15 15:30:49 +00:00
|
|
|
"dir": false,
|
|
|
|
"path": v,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
for _,v := range(dirs){
|
|
|
|
response = append(response, map[string]interface{}{
|
|
|
|
"dir": true,
|
|
|
|
"path": v,
|
2019-01-05 22:44:33 +00:00
|
|
|
})
|
|
|
|
}
|
2023-06-16 17:29:43 +00:00
|
|
|
files = files[:0]
|
|
|
|
dirs = dirs[:0]
|
2023-06-15 15:30:49 +00:00
|
|
|
// err := search.Search(d.user.Fs, r.URL.Path, query, d, func(path string, f os.FileInfo) error {
|
|
|
|
// response = append(response, map[string]interface{}{
|
|
|
|
// "dir": f.IsDir(),
|
|
|
|
// "path": path,
|
|
|
|
// })
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
// })
|
2019-01-05 22:44:33 +00:00
|
|
|
|
|
|
|
return renderJSON(w, r, response)
|
|
|
|
})
|