feat(admin): category content on the Blog Editor and editor image uploads

- category content is the blogeditor type (uploadFolder categories): it is
  stripped and reported like post content; the 422 CheckHTML gate is
  retired and blank content still becomes NULL
- blogeditor and mlblogeditor Upload: magic-byte check for JPEG, PNG, GIF
  and WebP matching the extension, safe lowercase names, storage through
  classes.StoreMedia in the field's uploadFolder
- TestBlogEditorUploadSmoke, TestCategoriesAdminContent asserts the strip,
  README describes the field types, admin saves and editor uploads
This commit is contained in:
2026-10-10 12:08:51 +02:00
parent 15fcad7a93
commit cb1c688213
8 changed files with 417 additions and 53 deletions

View File

@@ -5,7 +5,6 @@ import (
"errors"
"strings"
"git.golem15.com/golem15/sm-journal-plugin/classes"
"git.golem15.com/golem15/sm-journal-plugin/models"
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/cabana"
@@ -61,21 +60,20 @@ func (categoriesAdminController) FormBeforeUpdate(ctx context.Context, model any
return prepareCategoryWrite(cat)
}
// prepareCategoryWrite gates the category HTML body (D-21): blank content is
// stored as NULL, and content that fails classes.CheckHTML is a 422 on
// content. Any other content is stored exactly as submitted.
// prepareCategoryWrite stores blank category content (white space only) as
// NULL and accepts any other content it receives. Since Phase 16.2 the
// content field is the blogeditor type, whose Decode already stored the HTML
// policy's output (classes.SanitizeHTMLReport) and told the administrator
// what it removed, so an admin save is never refused because of markup
// (D-10 amended, see the bluemonday decision note). Rows written by SQL or
// by the import commands do not pass through here and are not sanitized by
// it.
func prepareCategoryWrite(cat *models.Category) error {
if cat.Content == nil {
return nil
}
if strings.TrimSpace(*cat.Content) == "" {
cat.Content = nil
return nil
}
if err := classes.CheckHTML(*cat.Content); err != nil {
return &cabana.ValidationError{Details: map[string]any{
"content": []string{err.Error()},
}}
}
return nil
}