photoprism/internal/entity/lens.go
Michael Mayer b37d4472e4 Backend: Use original file if thumb size exceeds limit #172
Plus some mutex and config refactoring along the way...

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-01-08 19:51:21 +01:00

60 lines
1.2 KiB
Go

package entity
import (
"strings"
"time"
"github.com/gosimple/slug"
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/mutex"
)
// Camera lens (as extracted from UpdateExif metadata)
type Lens struct {
ID uint `gorm:"primary_key"`
LensSlug string `gorm:"type:varbinary(128);unique_index;"`
LensModel string
LensMake string
LensType string
LensOwner string
LensDescription string `gorm:"type:text;"`
LensNotes string `gorm:"type:text;"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time `sql:"index"`
}
func (Lens) TableName() string {
return "lenses"
}
func NewLens(modelName string, makeName string) *Lens {
modelName = strings.TrimSpace(modelName)
makeName = strings.TrimSpace(makeName)
if modelName == "" {
modelName = "Unknown"
}
lensSlug := slug.MakeLang(modelName, "en")
result := &Lens{
LensModel: modelName,
LensMake: makeName,
LensSlug: lensSlug,
}
return result
}
func (m *Lens) FirstOrCreate(db *gorm.DB) *Lens {
mutex.Db.Lock()
defer mutex.Db.Unlock()
if err := db.FirstOrCreate(m, "lens_slug = ?", m.LensSlug).Error; err != nil {
log.Errorf("lens: %s", err)
}
return m
}