updated a few things
This commit is contained in:
parent
5338d0c79e
commit
6790b723a7
|
@ -1,8 +1,9 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"github.com/gtsteffaniak/filebrowser/search"
|
||||
"net/http"
|
||||
|
||||
"github.com/gtsteffaniak/filebrowser/search"
|
||||
)
|
||||
|
||||
var searchHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||
|
@ -10,13 +11,16 @@ var searchHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *dat
|
|||
query := r.URL.Query().Get("query")
|
||||
indexInfo, fileTypes := search.SearchAllIndexes(query, r.URL.Path)
|
||||
for _, path := range indexInfo {
|
||||
f := fileTypes[path]
|
||||
responseObj := map[string]interface{}{
|
||||
"path": path,
|
||||
"dir": true,
|
||||
}
|
||||
for filterType, _ := range f {
|
||||
if f[filterType] {
|
||||
responseObj[filterType] = f[filterType]
|
||||
if _, ok := fileTypes[path]; ok {
|
||||
responseObj["dir"] = false
|
||||
for filterType, value := range fileTypes[path] {
|
||||
if value {
|
||||
responseObj[filterType] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
response = append(response, responseObj)
|
||||
|
|
|
@ -137,19 +137,18 @@ func SearchAllIndexes(search string, scope string) ([]string, map[string]map[str
|
|||
pathName = pathName + "/"
|
||||
}
|
||||
if !strings.HasPrefix(pathName, scope) {
|
||||
// skip directory if not in scope
|
||||
continue
|
||||
}
|
||||
pathName = strings.TrimPrefix(pathName, scope)
|
||||
// check if dir matches
|
||||
matches, fileType = containsSearchTerm(pathName, searchTerm, *searchOptions, true)
|
||||
matches, _ = containsSearchTerm(pathName, searchTerm, *searchOptions, true)
|
||||
if matches {
|
||||
matching = append(matching, pathName)
|
||||
fileListTypes[pathName] = fileType
|
||||
count++
|
||||
}
|
||||
for _, fileName := range files {
|
||||
// check if file matches
|
||||
matches, fileType := containsSearchTerm(pathName+fileName, searchTerm, *searchOptions, false)
|
||||
matches, fileType = containsSearchTerm(pathName+fileName, searchTerm, *searchOptions, false)
|
||||
if !matches {
|
||||
continue
|
||||
}
|
||||
|
@ -198,7 +197,6 @@ func containsSearchTerm(pathName string, searchTerm string, options SearchOption
|
|||
// Calculate fileSize only if needed
|
||||
var fileSize int64
|
||||
if conditions["larger"] || conditions["smaller"] {
|
||||
log.Println(conditions)
|
||||
fileSize = getFileSize(pathName)
|
||||
}
|
||||
matchesAllConditions := true
|
||||
|
|
|
@ -218,7 +218,8 @@ export default {
|
|||
}
|
||||
|
||||
document.body.style.overflow = "auto";
|
||||
this.reset();
|
||||
this.ongoing = false;
|
||||
this.results = [];
|
||||
this.value = "";
|
||||
this.active = false;
|
||||
this.$refs.input.blur();
|
||||
|
@ -230,7 +231,8 @@ export default {
|
|||
},
|
||||
value() {
|
||||
if (this.results.length) {
|
||||
this.reset();
|
||||
this.ongoing = false;
|
||||
this.results = [];
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -284,17 +286,17 @@ export default {
|
|||
if (!str.includes("/")) {
|
||||
return "";
|
||||
}
|
||||
let parts = str.replace(/\/$/, "").split("/");
|
||||
let parts = str.replace(/(\/$|^\/)/, "").split("/"); //remove first and last slash
|
||||
parts.pop();
|
||||
return parts.join("/") + "/";
|
||||
parts = parts.join("/") + "/"
|
||||
if (str.endsWith("/")) {
|
||||
parts = "/" + parts // weird rtl bug
|
||||
}
|
||||
return parts;
|
||||
},
|
||||
baseName(str) {
|
||||
let parts = str.split("/");
|
||||
if (str.endsWith("/")) {
|
||||
return parts[parts.length - 2] + "/";
|
||||
} else {
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
let parts = str.replace(/(\/$|^\/)/, "").split("/")
|
||||
return parts.pop()
|
||||
},
|
||||
...mapMutations(["showHover", "closeHovers", "setReload"]),
|
||||
open() {
|
||||
|
@ -336,15 +338,12 @@ export default {
|
|||
resetButtonGroups() {
|
||||
this.isTypeSelectDisabled = false;
|
||||
},
|
||||
reset() {
|
||||
this.ongoing = false;
|
||||
this.results = [];
|
||||
},
|
||||
async submit(event) {
|
||||
this.showHelp = false;
|
||||
event.preventDefault();
|
||||
if (this.value === "" || this.value.length < 3) {
|
||||
reset();
|
||||
this.ongoing = false;
|
||||
this.results = [];
|
||||
this.noneMessage = "Not enough characters to search (min 3)"
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue