Moved perceptual hash from photo to file model; code clean-up (go fmt)
- Files might show different details of the full photo
This commit is contained in:
parent
660153e70c
commit
10859ee695
|
@ -9,7 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetPhotos (router *gin.RouterGroup, conf *photoprism.Config) {
|
func GetPhotos(router *gin.RouterGroup, conf *photoprism.Config) {
|
||||||
router.GET("/photos", func(c *gin.Context) {
|
router.GET("/photos", func(c *gin.Context) {
|
||||||
var form forms.PhotoSearchForm
|
var form forms.PhotoSearchForm
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ var MigrateCommand = cli.Command{
|
||||||
Action: migrateAction,
|
Action: migrateAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
func migrateAction (context *cli.Context) error {
|
func migrateAction(context *cli.Context) error {
|
||||||
conf := photoprism.NewConfig(context)
|
conf := photoprism.NewConfig(context)
|
||||||
|
|
||||||
fmt.Println("Migrating database...")
|
fmt.Println("Migrating database...")
|
||||||
|
|
|
@ -9,6 +9,7 @@ type File struct {
|
||||||
Photo *Photo
|
Photo *Photo
|
||||||
PhotoID uint
|
PhotoID uint
|
||||||
FilePrimary bool
|
FilePrimary bool
|
||||||
|
FileMissing bool
|
||||||
FileName string
|
FileName string
|
||||||
FileType string `gorm:"type:varchar(30)"`
|
FileType string `gorm:"type:varchar(30)"`
|
||||||
FileMime string `gorm:"type:varchar(50)"`
|
FileMime string `gorm:"type:varchar(50)"`
|
||||||
|
@ -17,5 +18,7 @@ type File struct {
|
||||||
FileOrientation int
|
FileOrientation int
|
||||||
FileAspectRatio float64
|
FileAspectRatio float64
|
||||||
FileHash string `gorm:"type:varchar(100);unique_index"`
|
FileHash string `gorm:"type:varchar(100);unique_index"`
|
||||||
|
FilePerceptualHash string
|
||||||
|
|
||||||
FileNotes string `gorm:"type:text;"`
|
FileNotes string `gorm:"type:text;"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ type Photo struct {
|
||||||
PhotoVibrantColor string
|
PhotoVibrantColor string
|
||||||
PhotoMutedColor string
|
PhotoMutedColor string
|
||||||
PhotoCanonicalName string
|
PhotoCanonicalName string
|
||||||
PhotoPerceptualHash string
|
|
||||||
PhotoFavorite bool
|
PhotoFavorite bool
|
||||||
PhotoLat float64
|
PhotoLat float64
|
||||||
PhotoLong float64
|
PhotoLong float64
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (m *MediaFile) GetExifData() (*ExifData, error) {
|
||||||
|
|
||||||
value := float64(number) / float64(denom)
|
value := float64(number) / float64(denom)
|
||||||
|
|
||||||
m.exifData.Aperture = math.Round(value * 1000) / 1000
|
m.exifData.Aperture = math.Round(value*1000) / 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
if focal, err := x.Get(exif.FocalLength); err == nil {
|
if focal, err := x.Get(exif.FocalLength); err == nil {
|
||||||
|
@ -99,7 +99,7 @@ func (m *MediaFile) GetExifData() (*ExifData, error) {
|
||||||
|
|
||||||
value := float64(number) / float64(denom)
|
value := float64(number) / float64(denom)
|
||||||
|
|
||||||
m.exifData.FocalLength = math.Round(value * 1000) / 1000
|
m.exifData.FocalLength = math.Round(value*1000) / 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
if tm, err := x.DateTime(); err == nil {
|
if tm, err := x.DateTime(); err == nil {
|
||||||
|
|
|
@ -81,11 +81,6 @@ func (i *Indexer) IndexMediaFile(mediaFile *MediaFile) string {
|
||||||
|
|
||||||
if photoQuery.Error != nil {
|
if photoQuery.Error != nil {
|
||||||
if jpeg, err := mediaFile.GetJpeg(); err == nil {
|
if jpeg, err := mediaFile.GetJpeg(); err == nil {
|
||||||
// Perceptual Hash
|
|
||||||
if perceptualHash, err := jpeg.GetPerceptualHash(); err == nil {
|
|
||||||
photo.PhotoPerceptualHash = perceptualHash
|
|
||||||
}
|
|
||||||
|
|
||||||
// Geo Location
|
// Geo Location
|
||||||
if exifData, err := jpeg.GetExifData(); err == nil {
|
if exifData, err := jpeg.GetExifData(); err == nil {
|
||||||
photo.PhotoLat = exifData.Lat
|
photo.PhotoLat = exifData.Lat
|
||||||
|
@ -159,13 +154,6 @@ func (i *Indexer) IndexMediaFile(mediaFile *MediaFile) string {
|
||||||
i.db.Create(&photo)
|
i.db.Create(&photo)
|
||||||
} else if time.Now().Sub(photo.UpdatedAt).Minutes() > 10 { // If updated more than 10 minutes ago
|
} else if time.Now().Sub(photo.UpdatedAt).Minutes() > 10 { // If updated more than 10 minutes ago
|
||||||
if jpeg, err := mediaFile.GetJpeg(); err == nil {
|
if jpeg, err := mediaFile.GetJpeg(); err == nil {
|
||||||
// Perceptual Hash
|
|
||||||
if photo.PhotoPerceptualHash == "" {
|
|
||||||
if perceptualHash, err := jpeg.GetPerceptualHash(); err == nil {
|
|
||||||
photo.PhotoPerceptualHash = perceptualHash
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PhotoColors
|
// PhotoColors
|
||||||
colorNames, photo.PhotoVibrantColor, photo.PhotoMutedColor = jpeg.GetColors()
|
colorNames, photo.PhotoVibrantColor, photo.PhotoMutedColor = jpeg.GetColors()
|
||||||
|
|
||||||
|
@ -206,6 +194,13 @@ func (i *Indexer) IndexMediaFile(mediaFile *MediaFile) string {
|
||||||
file.FileMime = mediaFile.GetMimeType()
|
file.FileMime = mediaFile.GetMimeType()
|
||||||
file.FileOrientation = mediaFile.GetOrientation()
|
file.FileOrientation = mediaFile.GetOrientation()
|
||||||
|
|
||||||
|
// Perceptual Hash
|
||||||
|
if file.FilePerceptualHash == "" && mediaFile.IsJpeg() {
|
||||||
|
if perceptualHash, err := mediaFile.GetPerceptualHash(); err == nil {
|
||||||
|
file.FilePerceptualHash = perceptualHash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if mediaFile.GetWidth() > 0 && mediaFile.GetHeight() > 0 {
|
if mediaFile.GetWidth() > 0 && mediaFile.GetHeight() > 0 {
|
||||||
file.FileWidth = mediaFile.GetWidth()
|
file.FileWidth = mediaFile.GetWidth()
|
||||||
file.FileHeight = mediaFile.GetHeight()
|
file.FileHeight = mediaFile.GetHeight()
|
||||||
|
|
|
@ -32,7 +32,6 @@ type PhotoSearchResult struct {
|
||||||
PhotoVibrantColor string
|
PhotoVibrantColor string
|
||||||
PhotoMutedColor string
|
PhotoMutedColor string
|
||||||
PhotoCanonicalName string
|
PhotoCanonicalName string
|
||||||
PhotoPerceptualHash string
|
|
||||||
PhotoLat float64
|
PhotoLat float64
|
||||||
PhotoLong float64
|
PhotoLong float64
|
||||||
PhotoFavorite bool
|
PhotoFavorite bool
|
||||||
|
@ -66,8 +65,11 @@ type PhotoSearchResult struct {
|
||||||
|
|
||||||
// File
|
// File
|
||||||
FileID uint
|
FileID uint
|
||||||
|
FilePrimary bool
|
||||||
|
FileMissing bool
|
||||||
FileName string
|
FileName string
|
||||||
FileHash string
|
FileHash string
|
||||||
|
FilePerceptualHash string
|
||||||
FileType string
|
FileType string
|
||||||
FileMime string
|
FileMime string
|
||||||
FileWidth int
|
FileWidth int
|
||||||
|
@ -92,7 +94,7 @@ func (s *Search) Photos(form PhotoSearchForm) ([]PhotoSearchResult, error) {
|
||||||
q := s.db.NewScope(nil).DB()
|
q := s.db.NewScope(nil).DB()
|
||||||
q = q.Table("photos").
|
q = q.Table("photos").
|
||||||
Select(`SQL_CALC_FOUND_ROWS photos.*,
|
Select(`SQL_CALC_FOUND_ROWS photos.*,
|
||||||
files.id AS file_id, files.file_name, files.file_hash, files.file_type, files.file_mime, files.file_width, files.file_height, files.file_aspect_ratio, files.file_orientation,
|
files.id AS file_id, files.file_primary, files.file_missing, files.file_name, files.file_hash, files.file_perceptual_hash, files.file_type, files.file_mime, files.file_width, files.file_height, files.file_aspect_ratio, files.file_orientation,
|
||||||
cameras.camera_make, cameras.camera_model,
|
cameras.camera_make, cameras.camera_model,
|
||||||
lenses.lens_make, lenses.lens_model,
|
lenses.lens_make, lenses.lens_model,
|
||||||
countries.country_name,
|
countries.country_name,
|
||||||
|
|
Loading…
Reference in a new issue