added to thumbnail & image url

Signed-off-by: Ben Hall <ben@benh.codes>
This commit is contained in:
Ben Hall 2025-01-21 21:16:10 +00:00
parent 98901b0714
commit 474a9bd408
2 changed files with 9 additions and 6 deletions

View File

@ -4,6 +4,10 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"regexp"
"strings"
"time"
"github.com/TicketsBot/GoPanel/app" "github.com/TicketsBot/GoPanel/app"
"github.com/TicketsBot/GoPanel/app/http/validation" "github.com/TicketsBot/GoPanel/app/http/validation"
"github.com/TicketsBot/GoPanel/app/http/validation/defaults" "github.com/TicketsBot/GoPanel/app/http/validation/defaults"
@ -15,9 +19,6 @@ import (
"github.com/rxdn/gdl/objects/channel" "github.com/rxdn/gdl/objects/channel"
"github.com/rxdn/gdl/objects/guild" "github.com/rxdn/gdl/objects/guild"
"github.com/rxdn/gdl/objects/interaction/component" "github.com/rxdn/gdl/objects/interaction/component"
"regexp"
"strings"
"time"
) )
func ApplyPanelDefaults(data *panelBody) { func ApplyPanelDefaults(data *panelBody) {
@ -171,8 +172,10 @@ var urlRegex = regexp.MustCompile(`^https?://([-a-zA-Z0-9@:%._+~#=]{1,256})\.[a-
func validateNullableUrl(url *string) validation.ValidationFunc { func validateNullableUrl(url *string) validation.ValidationFunc {
return func() error { return func() error {
if url != nil && (len(*url) > 255 || !urlRegex.MatchString(*url)) { if url != nil && (len(*url) > 255 || !urlRegex.MatchString(*url)) {
if *url != "%avatar_url%" {
return validation.NewInvalidInputError("Invalid URL") return validation.NewInvalidInputError("Invalid URL")
} }
}
return nil return nil
} }

View File

@ -12,8 +12,8 @@ type CustomEmbed struct {
Url *string `json:"url" validate:"omitempty,url,max=255"` Url *string `json:"url" validate:"omitempty,url,max=255"`
Colour Colour `json:"colour" validate:"gte=0,lte=16777215"` Colour Colour `json:"colour" validate:"gte=0,lte=16777215"`
Author Author `json:"author" validate:"dive"` Author Author `json:"author" validate:"dive"`
ImageUrl *string `json:"image_url" validate:"omitempty,url,max=255"` ImageUrl *string `json:"image_url" validate:"omitempty,max=255"`
ThumbnailUrl *string `json:"thumbnail_url" validate:"omitempty,url,max=255"` ThumbnailUrl *string `json:"thumbnail_url" validate:"omitempty,max=255"`
Footer Footer `json:"footer" validate:"dive"` Footer Footer `json:"footer" validate:"dive"`
Timestamp *DateTimeLocal `json:"timestamp" validate:"omitempty"` Timestamp *DateTimeLocal `json:"timestamp" validate:"omitempty"`
Fields []Field `json:"fields" validate:"dive,max=25"` Fields []Field `json:"fields" validate:"dive,max=25"`