From 33534728c8c767fcab05e1295f72aabfe08ca71d Mon Sep 17 00:00:00 2001 From: Vincent Boutour Date: Thu, 29 Dec 2022 12:42:14 +0100 Subject: [PATCH] feat(search): Adding basic saved search crud Signed-off-by: Vincent Boutour --- README.md | 2 + cmd/fibr/config.go | 3 + cmd/fibr/fibr.go | 3 +- cmd/fibr/templates/files.html | 21 ++++ .../templates/saved-search-folder-modal.html | 19 ---- cmd/fibr/templates/saved-search-modal.html | 39 +++++++ cmd/fibr/templates/search.html | 6 +- pkg/crud/create.go | 39 +++++++ pkg/crud/delete.go | 30 ++++- pkg/crud/get.go | 6 +- pkg/crud/list.go | 35 ++++-- pkg/crud/post.go | 11 +- pkg/provider/search.go | 11 ++ pkg/search/crud.go | 107 ++++++++++++++++++ pkg/search/search.go | 61 +++++++++- pkg/share/amqp.go | 4 +- pkg/share/crud.go | 7 +- pkg/share/share.go | 14 +-- pkg/webhook/amqp.go | 4 +- pkg/webhook/crud.go | 4 +- pkg/webhook/event.go | 4 +- pkg/webhook/webhook.go | 10 +- 22 files changed, 373 insertions(+), 67 deletions(-) delete mode 100644 cmd/fibr/templates/saved-search-folder-modal.html create mode 100644 cmd/fibr/templates/saved-search-modal.html create mode 100644 pkg/provider/search.go create mode 100644 pkg/search/crud.go diff --git a/README.md b/README.md index 3b54f5f7..27dc21c8 100644 --- a/README.md +++ b/README.md @@ -368,6 +368,8 @@ Usage of fibr: [redis] Redis Username, if any {FIBR_REDIS_USERNAME} -sanitizeOnStart [crud] Sanitize name on start {FIBR_SANITIZE_ON_START} + -searchAmqpExclusiveRoutingKey string + [search] AMQP Routing Key for exclusive lock on default exchange {FIBR_SEARCH_AMQP_EXCLUSIVE_ROUTING_KEY} (default "fibr.semaphore.search") -shareAmqpExchange string [share] AMQP Exchange Name {FIBR_SHARE_AMQP_EXCHANGE} (default "fibr.shares") -shareAmqpExclusiveRoutingKey string diff --git a/cmd/fibr/config.go b/cmd/fibr/config.go index 73513b96..b3007ca1 100644 --- a/cmd/fibr/config.go +++ b/cmd/fibr/config.go @@ -9,6 +9,7 @@ import ( basicMemory "github.com/ViBiOh/auth/v2/pkg/store/memory" "github.com/ViBiOh/fibr/pkg/crud" "github.com/ViBiOh/fibr/pkg/exif" + "github.com/ViBiOh/fibr/pkg/search" "github.com/ViBiOh/fibr/pkg/share" "github.com/ViBiOh/fibr/pkg/storage" "github.com/ViBiOh/fibr/pkg/thumbnail" @@ -51,6 +52,7 @@ type configuration struct { amqpShare amqphandler.Config amqpWebhook amqphandler.Config redis redis.Config + search search.Config disableAuth *bool } @@ -82,6 +84,7 @@ func newConfig() (configuration, error) { amqpShare: amqphandler.Flags(fs, "amqpShare", flags.NewOverride("Exchange", "fibr.shares"), flags.NewOverride("Queue", "fibr.share-"+generateIdentityName()), flags.NewOverride("RoutingKey", "share"), flags.NewOverride("Exclusive", true), flags.NewOverride("RetryInterval", time.Duration(0))), amqpWebhook: amqphandler.Flags(fs, "amqpWebhook", flags.NewOverride("Exchange", "fibr.webhooks"), flags.NewOverride("Queue", "fibr.webhook-"+generateIdentityName()), flags.NewOverride("RoutingKey", "webhook"), flags.NewOverride("Exclusive", true), flags.NewOverride("RetryInterval", time.Duration(0))), redis: redis.Flags(fs, "redis", flags.NewOverride("Address", "")), + search: search.Flags(fs, "search"), disableAuth: flags.Bool(fs, "", "auth", "NoAuth", "Disable basic authentification", false, nil), }, fs.Parse(os.Args[1:]) } diff --git a/cmd/fibr/fibr.go b/cmd/fibr/fibr.go index fe9d0594..86186483 100644 --- a/cmd/fibr/fibr.go +++ b/cmd/fibr/fibr.go @@ -114,7 +114,8 @@ func main() { amqpWebhookApp, err := amqphandler.New(config.amqpWebhook, client.amqp, client.tracer.GetTracer("amqp_handler_webhook"), webhookApp.AMQPHandler) logger.Fatal(err) - searchApp := search.New(filteredStorage, thumbnailApp, exifApp, client.tracer.GetTracer("search")) + searchApp, err := search.New(config.search, filteredStorage, thumbnailApp, exifApp, client.amqp, client.tracer.GetTracer("search")) + logger.Fatal(err) crudApp, err := crud.New(config.crud, storageApp, filteredStorage, rendererApp, shareApp, webhookApp, thumbnailApp, exifApp, searchApp, eventBus.Push, client.amqp, client.tracer.GetTracer("crud")) logger.Fatal(err) diff --git a/cmd/fibr/templates/files.html b/cmd/fibr/templates/files.html index 3c1b8662..949999d0 100644 --- a/cmd/fibr/templates/files.html +++ b/cmd/fibr/templates/files.html @@ -31,6 +31,12 @@ {{ template "webhook-list" . }} {{ end }} + {{ range .SavedSearches }} + {{ if $root.Request.CanEdit }} + {{ template "delete-saved-search-modal" . }} + {{ end }} + {{ end }} + {{ range .Files }} {{ if $root.Request.CanEdit }} {{ template "edit-modal" . }} @@ -205,6 +211,21 @@