Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed Mar 24, 2022
1 parent 51fd47f commit 00876ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
})
}
2 changes: 1 addition & 1 deletion pkg/handlers/initiate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 00876ae

Please sign in to comment.