Skip to content

Commit

Permalink
Allow more imagenames
Browse files Browse the repository at this point in the history
Imagenames must match the following pattern "^(\d+)([_-][a-zA-Z0-9-_]+)?$"
  • Loading branch information
jmatthiesen81 authored and shyim committed Apr 3, 2024
1 parent d15b56a commit 4e6638a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/account/account_producer_extension_info_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -336,6 +337,7 @@ func uploadImagesByDirectory(ctx context.Context, extensionId int, directory str
}

imagesLen := len(images) - 1
re := regexp.MustCompile(`^(\d+)([_-][a-zA-Z0-9-_]+)?$`)

for i, image := range images {
if image.IsDir() {
Expand All @@ -351,13 +353,20 @@ func uploadImagesByDirectory(ctx context.Context, extensionId int, directory str
return fmt.Errorf("cannot upload image %s to extension: %w", image.Name(), err)
}

priority, err := strconv.Atoi(fileName)
matches := re.FindStringSubmatch(fileName)

if err != nil {
if matches == nil {
logging.FromContext(ctx).Warnf("Invalid image name %s, skipping", image.Name())
continue
}

priority, err := strconv.Atoi(matches[1])

if err != nil {
logging.FromContext(ctx).Warnf("Unexpected error: \"%s\", skipping", err)
continue
}

apiImage.Priority = priority
apiImage.Details[0].Activated = false
apiImage.Details[0].Preview = false
Expand Down

0 comments on commit 4e6638a

Please sign in to comment.