From 1ba3108ae402f228f8eb56088ef7903898fbd02f Mon Sep 17 00:00:00 2001 From: RaviAnand Mohabir Date: Sun, 14 May 2023 13:50:56 +0200 Subject: [PATCH] feat(server): :sparkles: implement check for image mime types --- server/pkg/tags/commands.go | 12 ++++++++++++ server/pkg/tags/hooks.go | 12 ++++++++++++ server/pkg/tags/utils.go | 3 +++ 3 files changed, 27 insertions(+) create mode 100644 server/pkg/tags/utils.go diff --git a/server/pkg/tags/commands.go b/server/pkg/tags/commands.go index 251756b..1ad2a39 100644 --- a/server/pkg/tags/commands.go +++ b/server/pkg/tags/commands.go @@ -32,6 +32,18 @@ func RegisterCommands(app *pocketbase.PocketBase, taggerHost string) { continue } + var isImageType bool + for _, t := range imageMimeTypes { + if file.GetString("type") == t { + isImageType = true + continue + } + } + + if !isImageType { + continue + } + url, err := url.Parse(taggerHost) if err != nil { diff --git a/server/pkg/tags/hooks.go b/server/pkg/tags/hooks.go index a507e9a..355961f 100644 --- a/server/pkg/tags/hooks.go +++ b/server/pkg/tags/hooks.go @@ -32,6 +32,18 @@ func RegisterHooks(app *pocketbase.PocketBase, taggerHost string) { return nil } + var isImageType bool + for _, t := range imageMimeTypes { + if e.Record.GetString("type") == t { + isImageType = true + continue + } + } + + if !isImageType { + return nil + } + url, err := url.Parse(taggerHost) if err != nil { diff --git a/server/pkg/tags/utils.go b/server/pkg/tags/utils.go new file mode 100644 index 0000000..ebd0a9d --- /dev/null +++ b/server/pkg/tags/utils.go @@ -0,0 +1,3 @@ +package tags + +var imageMimeTypes = []string{"image/png", "image/gif", "image/jpeg", "image/svg+xml", "image/webp", "image/avif"}