photoprism/internal/form/lens.go
Keith Martin c3eda657fd
Metadata: Add Lens Make and Model updates via CLI & API #5644 #5656
Adds the ability to override a lens's Make/Model (e.g. fixing Pentax lenses that ExifTool decodes as `4 38`) via a new photoprism lenses update CLI command and a `PUT /api/v1/lenses/:id endpoint`, plus a `GET /api/v1/lenses` search endpoint, a new lenses ACL resource, and an lenses ls list command.
2026-06-15 09:37:32 +02:00

39 lines
863 B
Go

package form
import (
"github.com/ulule/deepcopier"
"github.com/photoprism/photoprism/pkg/i18n"
"github.com/photoprism/photoprism/pkg/txt"
)
// Lens represents a lens edit form.
type Lens struct {
LensMake string `json:"Make"`
LensModel string `json:"Model"`
}
// NewLens creates a new form struct based on the interface values.
func NewLens(m any) (*Lens, error) {
frm := &Lens{}
err := deepcopier.Copy(m).To(frm)
return frm, err
}
// Validate returns an error if any form values are invalid.
func (frm *Lens) Validate() error {
lensMake := txt.Clip(frm.LensMake, txt.ClipName)
lensModel := txt.Clip(frm.LensModel, txt.ClipName)
if lensMake == "" || lensModel == "" {
return i18n.Error(i18n.ErrInvalidName)
}
lensSlug := txt.Slug(lensMake + " " + lensModel)
if lensSlug == "" {
return i18n.Error(i18n.ErrInvalidName)
}
return nil
}