Update search behavior (#195)

This commit is contained in:
Graham Steffaniak 2024-08-24 19:12:47 -05:00 committed by GitHub
parent 5f185597c9
commit 74ccfab070
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 20 additions and 56 deletions

View File

@ -26,6 +26,13 @@ jobs:
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: gtstef/filebrowser images: gtstef/filebrowser
- name: Get latest release tag and commit SHA
id: get_tag_and_sha
run: |
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
latest_commit=$(git rev-list -n 1 $latest_tag)
echo "latest_tag=${latest_tag}" >> $GITHUB_ENV
echo "latest_commit=${latest_commit}" >> $GITHUB_ENV
- name: Build and push - name: Build and push
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:

View File

@ -360,7 +360,6 @@ func resolveSymlinks(path string) (string, error) {
// addContent reads and sets content based on the file type. // addContent reads and sets content based on the file type.
func (i *FileInfo) addContent(path string) error { func (i *FileInfo) addContent(path string) error {
if !i.IsDir { if !i.IsDir {
fmt.Println("getting content for ", path)
content, err := os.ReadFile(path) content, err := os.ReadFile(path)
if err != nil { if err != nil {
return err return err

View File

@ -65,7 +65,7 @@ func (si *Index) Search(search string, scope string, sourceSession string) ([]st
if count > maxSearchResults { if count > maxSearchResults {
break break
} }
fullName := pathName + file fullName := strings.TrimLeft(pathName+file, "/")
fileTypes := map[string]bool{} fileTypes := map[string]bool{}
matches, fileType := containsSearchTerm(fullName, searchTerm, *searchOptions, isDir, fileTypes) matches, fileType := containsSearchTerm(fullName, searchTerm, *searchOptions, isDir, fileTypes)

View File

@ -2,7 +2,6 @@ package http
import ( import (
"errors" "errors"
"fmt"
"log" "log"
"net/http" "net/http"
"net/url" "net/url"
@ -86,7 +85,6 @@ var rawHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data)
if err != nil { if err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }
fmt.Println("realpath", realPath, err)
file, err := files.FileInfoFaster(files.FileOptions{ file, err := files.FileInfoFaster(files.FileOptions{
Path: realPath, Path: realPath,
Modify: d.user.Perm.Modify, Modify: d.user.Perm.Modify,

View File

@ -152,7 +152,6 @@ var resourcePutHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
ReadHeader: d.server.TypeDetectionByHeader, ReadHeader: d.server.TypeDetectionByHeader,
Checker: d, Checker: d,
} }
fmt.Println("realPath", realPath)
err = files.WriteFile(fileOpts, r.Body) err = files.WriteFile(fileOpts, r.Body)
return errToStatus(err), err return errToStatus(err), err
}) })

View File

@ -15,11 +15,6 @@ export default async function search(base, query) {
data = data.map((item) => { data = data.map((item) => {
item.url = `/files${base}` + url.encodePath(item.path); item.url = `/files${base}` + url.encodePath(item.path);
if (item.dir) {
item.url += "/";
}
return item; return item;
}); });

View File

@ -1,7 +1,7 @@
<template> <template>
<div id="search" @click="open" :class="{ active, ongoing, 'dark-mode': isDarkMode }"> <div id="search" :class="{ active, ongoing, 'dark-mode': isDarkMode }">
<!-- Search input section --> <!-- Search input section -->
<div id="input"> <div id="input" @click="open">
<!-- Close button visible when search is active --> <!-- Close button visible when search is active -->
<button <button
v-if="active" v-if="active"
@ -34,13 +34,8 @@
<div class="button" style="width: 100%">Search Context: {{ getContext }}</div> <div class="button" style="width: 100%">Search Context: {{ getContext }}</div>
<!-- List of search results --> <!-- List of search results -->
<ul v-show="results.length > 0"> <ul v-show="results.length > 0">
<li <li v-for="(s, k) in results" :key="k" style="cursor: pointer">
v-for="(s, k) in results" <router-link :to="s.url">
:key="k"
@click.stop.prevent="navigateTo(s.url)"
style="cursor: pointer"
>
<router-link to="#" event="">
<i v-if="s.dir" class="material-icons folder-icons"> folder </i> <i v-if="s.dir" class="material-icons folder-icons"> folder </i>
<i v-else-if="s.audio" class="material-icons audio-icons"> volume_up </i> <i v-else-if="s.audio" class="material-icons audio-icons"> volume_up </i>
<i v-else-if="s.image" class="material-icons image-icons"> photo </i> <i v-else-if="s.image" class="material-icons image-icons"> photo </i>
@ -177,13 +172,8 @@
</div> </div>
<!-- List of search results --> <!-- List of search results -->
<ul v-show="results.length > 0"> <ul v-show="results.length > 0">
<li <li v-for="(s, k) in results" :key="k" style="cursor: pointer">
v-for="(s, k) in results" <router-link :to="s.url">
:key="k"
@click.stop.prevent="navigateTo(s.url)"
style="cursor: pointer"
>
<router-link to="#" event="">
<i v-if="s.dir" class="material-icons folder-icons"> folder </i> <i v-if="s.dir" class="material-icons folder-icons"> folder </i>
<i v-else-if="s.audio" class="material-icons audio-icons"> volume_up </i> <i v-else-if="s.audio" class="material-icons audio-icons"> volume_up </i>
<i v-else-if="s.image" class="material-icons image-icons"> photo </i> <i v-else-if="s.image" class="material-icons image-icons"> photo </i>
@ -267,25 +257,6 @@ export default {
resultList.classList.add("active"); resultList.classList.add("active");
}, 100); }, 100);
}, },
currentPrompt(val, old) {
this.active = val?.prompt === "search";
if (old?.prompt === "search" && !this.active) {
if (this.reload) {
this.setReload(true);
}
document.body.style.overflow = "auto";
this.ongoing = false;
this.results = [];
this.value = "";
this.active = false;
this.$refs.input.blur();
} else if (this.active) {
this.reload = false;
this.$refs.input.focus();
document.body.style.overflow = "hidden";
}
},
value() { value() {
if (this.results.length) { if (this.results.length) {
this.ongoing = false; this.ongoing = false;
@ -303,9 +274,6 @@ export default {
active() { active() {
return getters.currentPromptName() == "search"; return getters.currentPromptName() == "search";
}, },
showOverlay() {
return getters.currentPrompt() !== null && getters.currentPromptName() !== "more";
},
isDarkMode() { isDarkMode() {
return getters.isDarkMode(); return getters.isDarkMode();
}, },
@ -342,11 +310,6 @@ export default {
}, },
}, },
methods: { methods: {
async navigateTo(url) {
mutations.closeHovers();
await this.$nextTick();
setTimeout(() => this.$router.push(url), 10);
},
basePath(str, isDir) { basePath(str, isDir) {
let parts = str.replace(/(\/$|^\/)/, "").split("/"); let parts = str.replace(/(\/$|^\/)/, "").split("/");
if (parts.length <= 1) { if (parts.length <= 1) {
@ -360,6 +323,7 @@ export default {
if (isDir) { if (isDir) {
parts = "/" + parts; // fix weird rtl thing parts = "/" + parts; // fix weird rtl thing
} }
return parts; return parts;
}, },
baseName(str) { baseName(str) {
@ -367,7 +331,9 @@ export default {
return parts.pop(); return parts.pop();
}, },
open() { open() {
mutations.showHover("search"); if (!this.active) {
mutations.showHover("search");
}
}, },
close(event) { close(event) {
this.value = ""; this.value = "";

View File

@ -87,7 +87,6 @@ export default {
}, },
computed: { computed: {
isLoaded() { isLoaded() {
console.log(state.loading);
return !("preview-img" in state.loading); return !("preview-img" in state.loading);
}, },
}, },

View File

@ -2,6 +2,7 @@
<div class="card clickable" style="min-height: 4em"> <div class="card clickable" style="min-height: 4em">
<div class="card-wrapper user-card"> <div class="card-wrapper user-card">
<div @click="navigateTo('/settings#profile-main')" class="inner-card"> <div @click="navigateTo('/settings#profile-main')" class="inner-card">
<i class="material-icons">person</i>
{{ user.username }} {{ user.username }}
<i class="material-icons">settings</i> <i class="material-icons">settings</i>
</div> </div>
@ -208,7 +209,6 @@ export default {
if (this.disableUsedPercentage) { if (this.disableUsedPercentage) {
return usageStats; return usageStats;
} }
console.log("Fetching usage for", path, state.user);
try { try {
let usage = await files.usage(path); let usage = await files.usage(path);
usageStats = { usageStats = {

View File

@ -134,6 +134,7 @@ async function initAuth() {
} }
router.beforeResolve(async (to, from, next) => { router.beforeResolve(async (to, from, next) => {
mutations.closeHovers()
const title = i18n.global.t(titles[to.name as keyof typeof titles]); const title = i18n.global.t(titles[to.name as keyof typeof titles]);
document.title = title + " - " + name; document.title = title + " - " + name;
mutations.setRoute(to) mutations.setRoute(to)