From 00876ae05a2bfe64ead1465496c0f58b3a87be3e Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 24 Mar 2022 08:55:19 +0100 Subject: [PATCH] minor refactoring --- pkg/config/config.go | 2 +- pkg/handlers/config.go | 10 ++++++++++ pkg/handlers/initiate.go | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 108e0a4..77b5198 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -119,7 +119,7 @@ func (c *S3Config) GetObjectURL(key string) *url.URL { return u } -func (c *expiration) Supported(cls string) bool { +func (c *expiration) HasClass(cls string) bool { for _, c := range c.Classes { if c.Tag == cls { return true diff --git a/pkg/handlers/config.go b/pkg/handlers/config.go index 3de044e..0106204 100644 --- a/pkg/handlers/config.go +++ b/pkg/handlers/config.go @@ -5,8 +5,14 @@ import ( "github.com/stv0g/gose/pkg/config" ) +type featureResponse struct { + Shortener bool `json:"shortener"` + NotifyMail bool `json:"notify_mail"` +} + type configResponse struct { ExpirationClasses []config.ExpirationClass `json:"expiration_classes"` + Features featureResponse `json:"features"` } // HandleConfig returns runtime configuration to the frontend @@ -15,5 +21,9 @@ func HandleConfig(c *gin.Context) { c.JSON(200, &configResponse{ ExpirationClasses: cfg.S3.Expiration.Classes, + Features: featureResponse{ + Shortener: cfg.Shortener != nil, + NotifyMail: false, + }, }) } diff --git a/pkg/handlers/initiate.go b/pkg/handlers/initiate.go index 324f121..ed9b400 100644 --- a/pkg/handlers/initiate.go +++ b/pkg/handlers/initiate.go @@ -90,7 +90,7 @@ func HandleInitiate(c *gin.Context) { if req.Expiration == nil { expiration = cfg.S3.Expiration.Default } else { - if !cfg.S3.Expiration.Supported(*req.Expiration) { + if !cfg.S3.Expiration.HasClass(*req.Expiration) { c.JSON(http.StatusInternalServerError, gin.H{"error": "invalid expiration class"}) return }