mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-03 20:12:59 +00:00
fet
This commit is contained in:
@@ -191,32 +191,46 @@ func UpdateBannerHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Log form values for debugging
|
// Log form values for debugging
|
||||||
log.Printf("Form values: %+v", r.Form)
|
log.Printf("Form values: %+v", r.Form)
|
||||||
|
|
||||||
|
// Helper function to get form value with case-insensitive key matching
|
||||||
|
getFormValue := func(keys ...string) string {
|
||||||
|
for _, key := range keys {
|
||||||
|
if val := r.FormValue(key); val != "" {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get style values with case-insensitive fallback
|
||||||
|
styleBgColor := getFormValue("Style[BackgroundColor]", "style[backgroundcolor]")
|
||||||
|
styleTextColor := getFormValue("Style[TextColor]", "style[textcolor]")
|
||||||
|
|
||||||
// Create a new banner with default values
|
// Create a new banner with default values
|
||||||
newBanner := BannerContent{
|
newBanner := BannerContent{
|
||||||
Text: r.FormValue("Text"),
|
Text: getFormValue("Text"),
|
||||||
Link: r.FormValue("Link"),
|
Link: getFormValue("Link"),
|
||||||
Style: BannerStyle{
|
Style: BannerStyle{
|
||||||
// Parse style values from form
|
// Parse style values from form with case-insensitive fallback
|
||||||
BackgroundColor: r.FormValue("style[BackgroundColor]"),
|
BackgroundColor: styleBgColor,
|
||||||
TextColor: r.FormValue("style[TextColor]"),
|
TextColor: styleTextColor,
|
||||||
TextAlign: r.FormValue("style[TextAlign]"),
|
TextAlign: getFormValue("Style[TextAlign]", "style[textalign]", "left"),
|
||||||
FontSize: r.FormValue("style[FontSize]"),
|
FontSize: getFormValue("Style[FontSize]", "style[fontsize]", "16px"),
|
||||||
Padding: r.FormValue("style[Padding]"),
|
Padding: getFormValue("Style[Padding]", "style[padding]", "10px"),
|
||||||
Margin: r.FormValue("style[Margin]"),
|
Margin: getFormValue("Style[Margin]", "style[margin]", "0"),
|
||||||
BorderRadius: r.FormValue("style[BorderRadius]"),
|
BorderRadius: getFormValue("Style[BorderRadius]", "style[borderradius]", "0"),
|
||||||
IsVisible: r.FormValue("IsVisible") == "true" || r.FormValue("style[IsVisible]") == "true",
|
IsVisible: getFormValue("IsVisible", "style[IsVisible]", "style[isvisible]") == "true",
|
||||||
// Add image position fields
|
// Add image position fields
|
||||||
ImagePosition: r.FormValue("style[ImagePosition]"),
|
ImagePosition: getFormValue("Style[ImagePosition]", "style[imageposition]", "right"),
|
||||||
ImageX: parseIntOrDefault(r.FormValue("style[ImageX]"), 0),
|
ImageX: parseIntOrDefault(getFormValue("Style[ImageX]", "style[imagex]"), 0),
|
||||||
ImageY: parseIntOrDefault(r.FormValue("style[ImageY]"), 0),
|
ImageY: parseIntOrDefault(getFormValue("Style[ImageY]", "style[imagey]"), 0),
|
||||||
// Additional style fields
|
// Additional style fields
|
||||||
Background: r.FormValue("style[Background]"),
|
Background: getFormValue("Style[Background]", "style[background]"),
|
||||||
ContainerStyle: r.FormValue("style[ContainerStyle]"),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the background style (gradient or solid color)
|
// Handle background style (gradient or solid color)
|
||||||
if bgStyle := r.FormValue("style[background]"); bgStyle != "" {
|
bgStyle := newBanner.Style.Background
|
||||||
|
if bgStyle != "" {
|
||||||
if strings.Contains(bgStyle, "gradient") {
|
if strings.Contains(bgStyle, "gradient") {
|
||||||
// If it's a gradient, use it as is
|
// If it's a gradient, use it as is
|
||||||
newBanner.Style.BackgroundColor = bgStyle
|
newBanner.Style.BackgroundColor = bgStyle
|
||||||
@@ -226,14 +240,8 @@ func UpdateBannerHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle container style if present
|
// Log the final banner data for debugging
|
||||||
if containerStyle := r.FormValue("style[containerStyle]"); containerStyle != "" {
|
log.Printf("Final banner data: %+v", newBanner)
|
||||||
// You can parse additional styles from containerStyle if needed
|
|
||||||
log.Printf("Container style received: %s", containerStyle)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log the banner data for debugging
|
|
||||||
log.Printf("Parsed banner data: %+v", newBanner)
|
|
||||||
|
|
||||||
// Handle file upload
|
// Handle file upload
|
||||||
file, handler, err := r.FormFile("image")
|
file, handler, err := r.FormFile("image")
|
||||||
|
|||||||
Reference in New Issue
Block a user