updated a few things

This commit is contained in:
Graham Steffaniak 2023-08-12 17:21:31 -05:00
parent 5338d0c79e
commit 6790b723a7
3 changed files with 26 additions and 25 deletions

View File

@ -1,8 +1,9 @@
package http package http
import ( import (
"github.com/gtsteffaniak/filebrowser/search"
"net/http" "net/http"
"github.com/gtsteffaniak/filebrowser/search"
) )
var searchHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { 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") query := r.URL.Query().Get("query")
indexInfo, fileTypes := search.SearchAllIndexes(query, r.URL.Path) indexInfo, fileTypes := search.SearchAllIndexes(query, r.URL.Path)
for _, path := range indexInfo { for _, path := range indexInfo {
f := fileTypes[path]
responseObj := map[string]interface{}{ responseObj := map[string]interface{}{
"path": path, "path": path,
"dir": true,
} }
for filterType, _ := range f { if _, ok := fileTypes[path]; ok {
if f[filterType] { responseObj["dir"] = false
responseObj[filterType] = f[filterType] for filterType, value := range fileTypes[path] {
if value {
responseObj[filterType] = value
}
} }
} }
response = append(response, responseObj) response = append(response, responseObj)

View File

@ -137,19 +137,18 @@ func SearchAllIndexes(search string, scope string) ([]string, map[string]map[str
pathName = pathName + "/" pathName = pathName + "/"
} }
if !strings.HasPrefix(pathName, scope) { if !strings.HasPrefix(pathName, scope) {
// skip directory if not in scope
continue continue
} }
pathName = strings.TrimPrefix(pathName, scope)
// check if dir matches // check if dir matches
matches, fileType = containsSearchTerm(pathName, searchTerm, *searchOptions, true) matches, _ = containsSearchTerm(pathName, searchTerm, *searchOptions, true)
if matches { if matches {
matching = append(matching, pathName) matching = append(matching, pathName)
fileListTypes[pathName] = fileType
count++ count++
} }
for _, fileName := range files { for _, fileName := range files {
// check if file matches // check if file matches
matches, fileType := containsSearchTerm(pathName+fileName, searchTerm, *searchOptions, false) matches, fileType = containsSearchTerm(pathName+fileName, searchTerm, *searchOptions, false)
if !matches { if !matches {
continue continue
} }
@ -198,7 +197,6 @@ func containsSearchTerm(pathName string, searchTerm string, options SearchOption
// Calculate fileSize only if needed // Calculate fileSize only if needed
var fileSize int64 var fileSize int64
if conditions["larger"] || conditions["smaller"] { if conditions["larger"] || conditions["smaller"] {
log.Println(conditions)
fileSize = getFileSize(pathName) fileSize = getFileSize(pathName)
} }
matchesAllConditions := true matchesAllConditions := true

View File

@ -218,7 +218,8 @@ export default {
} }
document.body.style.overflow = "auto"; document.body.style.overflow = "auto";
this.reset(); this.ongoing = false;
this.results = [];
this.value = ""; this.value = "";
this.active = false; this.active = false;
this.$refs.input.blur(); this.$refs.input.blur();
@ -230,7 +231,8 @@ export default {
}, },
value() { value() {
if (this.results.length) { if (this.results.length) {
this.reset(); this.ongoing = false;
this.results = [];
} }
}, },
}, },
@ -284,17 +286,17 @@ export default {
if (!str.includes("/")) { if (!str.includes("/")) {
return ""; return "";
} }
let parts = str.replace(/\/$/, "").split("/"); let parts = str.replace(/(\/$|^\/)/, "").split("/"); //remove first and last slash
parts.pop(); parts.pop();
return parts.join("/") + "/"; parts = parts.join("/") + "/"
if (str.endsWith("/")) {
parts = "/" + parts // weird rtl bug
}
return parts;
}, },
baseName(str) { baseName(str) {
let parts = str.split("/"); let parts = str.replace(/(\/$|^\/)/, "").split("/")
if (str.endsWith("/")) { return parts.pop()
return parts[parts.length - 2] + "/";
} else {
return parts[parts.length - 1];
}
}, },
...mapMutations(["showHover", "closeHovers", "setReload"]), ...mapMutations(["showHover", "closeHovers", "setReload"]),
open() { open() {
@ -336,15 +338,12 @@ export default {
resetButtonGroups() { resetButtonGroups() {
this.isTypeSelectDisabled = false; this.isTypeSelectDisabled = false;
}, },
reset() {
this.ongoing = false;
this.results = [];
},
async submit(event) { async submit(event) {
this.showHelp = false; this.showHelp = false;
event.preventDefault(); event.preventDefault();
if (this.value === "" || this.value.length < 3) { if (this.value === "" || this.value.length < 3) {
reset(); this.ongoing = false;
this.results = [];
this.noneMessage = "Not enough characters to search (min 3)" this.noneMessage = "Not enough characters to search (min 3)"
return return
} }