diff --git a/cmd/fibr/templates/search-modal.html b/cmd/fibr/templates/search-modal.html index f32f6479..aea1eb1b 100644 --- a/cmd/fibr/templates/search-modal.html +++ b/cmd/fibr/templates/search-modal.html @@ -27,6 +27,11 @@
+ + +
+diff --git a/cmd/fibr/templates/search.html b/cmd/fibr/templates/search.html index 0bf99c8b..371c54c0 100644 --- a/cmd/fibr/templates/search.html +++ b/cmd/fibr/templates/search.html @@ -121,6 +121,16 @@ + + {{ if .Tags }} + {{- if eq $root.Request.Display "grid" -}} + + {{ else }} + + #{{ join .Tags " #" }} + + {{ end}} + {{ end }} {{ end }} diff --git a/pkg/crud/get.go b/pkg/crud/get.go index a2ebf783..ac2c693c 100644 --- a/pkg/crud/get.go +++ b/pkg/crud/get.go @@ -132,19 +132,7 @@ func (a App) handleDir(w http.ResponseWriter, r *http.Request, request provider. go a.notify(tracer.CopyToBackground(r.Context()), provider.NewAccessEvent(item, r)) if query.GetBool(r, "search") { - files, hasMap, err := a.searchApp.Search(r, request, items) - if err != nil { - return errorReturn(request, err) - } - - return renderer.NewPage("search", http.StatusOK, map[string]any{ - "Paths": getPathParts(request), - "Files": files, - "Cover": a.getCover(r.Context(), request, items), - "Search": r.URL.Query(), - "Request": request, - "HasMap": hasMap, - }), nil + return a.search(r, request, item, items) } provider.SetPrefsCookie(w, request) diff --git a/pkg/crud/search.go b/pkg/crud/search.go new file mode 100644 index 00000000..df6620ec --- /dev/null +++ b/pkg/crud/search.go @@ -0,0 +1,52 @@ +package crud + +import ( + "net/http" + + absto "github.com/ViBiOh/absto/pkg/model" + "github.com/ViBiOh/fibr/pkg/provider" + "github.com/ViBiOh/fibr/pkg/thumbnail" + "github.com/ViBiOh/httputils/v4/pkg/renderer" + "github.com/ViBiOh/httputils/v4/pkg/tracer" +) + +func (a App) search(r *http.Request, request provider.Request, item absto.Item, files []absto.Item) (renderer.Page, error) { + ctx, end := tracer.StartSpan(r.Context(), a.tracer, "search") + defer end() + + metadatas, err := a.metadataApp.GetAllMetadataFor(ctx, files...) + if err != nil { + listLogger(item.Pathname).Error("list metadatas: %s", err) + } + + items := make([]provider.RenderItem, len(files)) + var hasMap bool + + renderWithThumbnail := request.Display == provider.GridDisplay + + for i, item := range files { + renderItem := provider.StorageToRender(item, request) + + metadata := metadatas[item.ID] + renderItem.Tags = metadata.Tags + + if renderWithThumbnail && a.thumbnailApp.CanHaveThumbnail(item) && a.thumbnailApp.HasThumbnail(ctx, item, thumbnail.SmallSize) { + renderItem.HasThumbnail = true + } + + items[i] = renderItem + + if !hasMap && metadata.Geocode.Longitude != 0 && metadata.Geocode.Latitude != 0 { + hasMap = true + } + } + + return renderer.NewPage("search", http.StatusOK, map[string]any{ + "Paths": getPathParts(request), + "Files": items, + "Cover": a.getCover(ctx, request, files), + "Search": r.URL.Query(), + "Request": request, + "HasMap": hasMap, + }), nil +} diff --git a/pkg/search/model.go b/pkg/search/model.go index 2d755830..e58b7b8b 100644 --- a/pkg/search/model.go +++ b/pkg/search/model.go @@ -40,6 +40,10 @@ func parseSearch(params url.Values, now time.Time) (output search, err error) { } } + if tags := strings.TrimSpace(params.Get("tags")); len(tags) > 0 { + output.tags = strings.Split(tags, " ") + } + output.before, err = parseDate(strings.TrimSpace(params.Get("before"))) if err != nil { return diff --git a/pkg/search/search.go b/pkg/search/search.go index c945a4da..1e490242 100644 --- a/pkg/search/search.go +++ b/pkg/search/search.go @@ -68,31 +68,3 @@ func (a App) Files(r *http.Request, request provider.Request) (items []absto.Ite return } - -func (a App) Search(r *http.Request, request provider.Request, files []absto.Item) ([]provider.RenderItem, bool, error) { - ctx, end := tracer.StartSpan(r.Context(), a.tracer, "search") - defer end() - - items := make([]provider.RenderItem, len(files)) - var hasMap bool - - renderWithThumbnail := request.Display == provider.GridDisplay - - for i, item := range files { - renderItem := provider.StorageToRender(item, request) - - if renderWithThumbnail && a.thumbnailApp.CanHaveThumbnail(item) && a.thumbnailApp.HasThumbnail(ctx, item, thumbnail.SmallSize) { - renderItem.HasThumbnail = true - } - - items[i] = renderItem - - if !hasMap { - if exif, err := a.exifApp.GetMetadataFor(ctx, item); err == nil && exif.Geocode.Longitude != 0 && exif.Geocode.Latitude != 0 { - hasMap = true - } - } - } - - return items, hasMap, nil -}