Files
photoprism/internal/form/label.go
2025-02-04 03:35:01 +01:00

45 lines
1.1 KiB
Go

package form
import (
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/i18n"
"github.com/photoprism/photoprism/pkg/txt"
"github.com/ulule/deepcopier"
)
// Label represents a label edit form.
type Label struct {
LabelName string `json:"Name"`
LabelPriority int `json:"Priority"`
LabelFavorite bool `json:"Favorite"`
LabelDescription string `json:"Description"`
LabelNotes string `json:"Notes"`
Thumb string `json:"Thumb"`
ThumbSrc string `json:"ThumbSrc"`
Uncertainty int `json:"Uncertainty"`
}
// NewLabel creates a new form struct based on the interface values.
func NewLabel(m interface{}) (*Label, error) {
frm := &Label{}
err := deepcopier.Copy(m).To(frm)
return frm, err
}
// Validate returns an error if any form values are invalid.
func (frm *Label) Validate() error {
labelName := txt.Clip(clean.NameCapitalized(frm.LabelName), txt.ClipName)
if labelName == "" {
return i18n.Error(i18n.ErrInvalidName)
}
labelSlug := txt.Slug(labelName)
if labelSlug == "" {
return i18n.Error(i18n.ErrInvalidName)
}
return nil
}