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
|
@ -27,4 +27,4 @@ func main() {
|
|||
}
|
||||
|
||||
app.Run(os.Args)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
func GetPhotos (router *gin.RouterGroup, conf *photoprism.Config) {
|
||||
func GetPhotos(router *gin.RouterGroup, conf *photoprism.Config) {
|
||||
router.GET("/photos", func(c *gin.Context) {
|
||||
var form forms.PhotoSearchForm
|
||||
|
||||
|
@ -28,4 +28,4 @@ func GetPhotos (router *gin.RouterGroup, conf *photoprism.Config) {
|
|||
|
||||
c.JSON(http.StatusOK, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
)
|
||||
|
||||
var ExportCommand = cli.Command{
|
||||
Name: "export",
|
||||
Usage: "Exports photos as JPEG",
|
||||
Flags: exportFlags,
|
||||
Name: "export",
|
||||
Usage: "Exports photos as JPEG",
|
||||
Flags: exportFlags,
|
||||
Action: exportAction,
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ import (
|
|||
)
|
||||
|
||||
var MigrateCommand = cli.Command{
|
||||
Name: "migrate",
|
||||
Usage: "Automatically migrates / initializes database",
|
||||
Name: "migrate",
|
||||
Usage: "Automatically migrates / initializes database",
|
||||
Action: migrateAction,
|
||||
}
|
||||
|
||||
func migrateAction (context *cli.Context) error {
|
||||
func migrateAction(context *cli.Context) error {
|
||||
conf := photoprism.NewConfig(context)
|
||||
|
||||
fmt.Println("Migrating database...")
|
||||
|
|
|
@ -8,8 +8,8 @@ type Album struct {
|
|||
gorm.Model
|
||||
AlbumSlug string
|
||||
AlbumName string
|
||||
AlbumDescription string `gorm:"type:text;"`
|
||||
AlbumNotes string `gorm:"type:text;"`
|
||||
AlbumDescription string `gorm:"type:text;"`
|
||||
AlbumNotes string `gorm:"type:text;"`
|
||||
AlbumPhoto *Photo
|
||||
AlbumPhotoID uint
|
||||
Photos []Photo `gorm:"many2many:album_photos;"`
|
||||
|
|
|
@ -6,16 +6,19 @@ import (
|
|||
|
||||
type File struct {
|
||||
gorm.Model
|
||||
Photo *Photo
|
||||
PhotoID uint
|
||||
FilePrimary bool
|
||||
FileName string
|
||||
FileType string `gorm:"type:varchar(30)"`
|
||||
FileMime string `gorm:"type:varchar(50)"`
|
||||
FileWidth int
|
||||
FileHeight int
|
||||
FileOrientation int
|
||||
FileAspectRatio float64
|
||||
FileHash string `gorm:"type:varchar(100);unique_index"`
|
||||
FileNotes string `gorm:"type:text;"`
|
||||
Photo *Photo
|
||||
PhotoID uint
|
||||
FilePrimary bool
|
||||
FileMissing bool
|
||||
FileName string
|
||||
FileType string `gorm:"type:varchar(30)"`
|
||||
FileMime string `gorm:"type:varchar(50)"`
|
||||
FileWidth int
|
||||
FileHeight int
|
||||
FileOrientation int
|
||||
FileAspectRatio float64
|
||||
FileHash string `gorm:"type:varchar(100);unique_index"`
|
||||
FilePerceptualHash string
|
||||
|
||||
FileNotes string `gorm:"type:text;"`
|
||||
}
|
||||
|
|
|
@ -7,33 +7,32 @@ import (
|
|||
|
||||
type Photo struct {
|
||||
gorm.Model
|
||||
TakenAt time.Time
|
||||
PhotoTitle string
|
||||
PhotoTitleChanged bool
|
||||
PhotoDescription string `gorm:"type:text;"`
|
||||
PhotoNotes string `gorm:"type:text;"`
|
||||
PhotoArtist string
|
||||
PhotoColors string
|
||||
PhotoVibrantColor string
|
||||
PhotoMutedColor string
|
||||
PhotoCanonicalName string
|
||||
PhotoPerceptualHash string
|
||||
PhotoFavorite bool
|
||||
PhotoLat float64
|
||||
PhotoLong float64
|
||||
PhotoFocalLength float64
|
||||
PhotoAperture float64
|
||||
Camera *Camera
|
||||
CameraID uint
|
||||
Lens *Lens
|
||||
LensID uint
|
||||
Country *Country
|
||||
CountryID string
|
||||
CountryChanged bool
|
||||
Location *Location
|
||||
LocationID uint
|
||||
LocationChanged bool
|
||||
Tags []*Tag `gorm:"many2many:photo_tags;"`
|
||||
Files []*File
|
||||
Albums []*Album `gorm:"many2many:album_photos;"`
|
||||
TakenAt time.Time
|
||||
PhotoTitle string
|
||||
PhotoTitleChanged bool
|
||||
PhotoDescription string `gorm:"type:text;"`
|
||||
PhotoNotes string `gorm:"type:text;"`
|
||||
PhotoArtist string
|
||||
PhotoColors string
|
||||
PhotoVibrantColor string
|
||||
PhotoMutedColor string
|
||||
PhotoCanonicalName string
|
||||
PhotoFavorite bool
|
||||
PhotoLat float64
|
||||
PhotoLong float64
|
||||
PhotoFocalLength float64
|
||||
PhotoAperture float64
|
||||
Camera *Camera
|
||||
CameraID uint
|
||||
Lens *Lens
|
||||
LensID uint
|
||||
Country *Country
|
||||
CountryID string
|
||||
CountryChanged bool
|
||||
Location *Location
|
||||
LocationID uint
|
||||
LocationChanged bool
|
||||
Tags []*Tag `gorm:"many2many:photo_tags;"`
|
||||
Files []*File
|
||||
Albums []*Album `gorm:"many2many:album_photos;"`
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ func (m *MediaFile) GetExifData() (*ExifData, error) {
|
|||
|
||||
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 {
|
||||
|
@ -99,7 +99,7 @@ func (m *MediaFile) GetExifData() (*ExifData, error) {
|
|||
|
||||
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 {
|
||||
|
|
|
@ -81,11 +81,6 @@ func (i *Indexer) IndexMediaFile(mediaFile *MediaFile) string {
|
|||
|
||||
if photoQuery.Error != nil {
|
||||
if jpeg, err := mediaFile.GetJpeg(); err == nil {
|
||||
// Perceptual Hash
|
||||
if perceptualHash, err := jpeg.GetPerceptualHash(); err == nil {
|
||||
photo.PhotoPerceptualHash = perceptualHash
|
||||
}
|
||||
|
||||
// Geo Location
|
||||
if exifData, err := jpeg.GetExifData(); err == nil {
|
||||
photo.PhotoLat = exifData.Lat
|
||||
|
@ -159,13 +154,6 @@ func (i *Indexer) IndexMediaFile(mediaFile *MediaFile) string {
|
|||
i.db.Create(&photo)
|
||||
} else if time.Now().Sub(photo.UpdatedAt).Minutes() > 10 { // If updated more than 10 minutes ago
|
||||
if jpeg, err := mediaFile.GetJpeg(); err == nil {
|
||||
// Perceptual Hash
|
||||
if photo.PhotoPerceptualHash == "" {
|
||||
if perceptualHash, err := jpeg.GetPerceptualHash(); err == nil {
|
||||
photo.PhotoPerceptualHash = perceptualHash
|
||||
}
|
||||
}
|
||||
|
||||
// PhotoColors
|
||||
colorNames, photo.PhotoVibrantColor, photo.PhotoMutedColor = jpeg.GetColors()
|
||||
|
||||
|
@ -206,6 +194,13 @@ func (i *Indexer) IndexMediaFile(mediaFile *MediaFile) string {
|
|||
file.FileMime = mediaFile.GetMimeType()
|
||||
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 {
|
||||
file.FileWidth = mediaFile.GetWidth()
|
||||
file.FileHeight = mediaFile.GetHeight()
|
||||
|
|
|
@ -19,23 +19,22 @@ type SearchCount struct {
|
|||
|
||||
type PhotoSearchResult struct {
|
||||
// Photo
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt time.Time
|
||||
TakenAt time.Time
|
||||
PhotoTitle string
|
||||
PhotoDescription string
|
||||
PhotoArtist string
|
||||
PhotoKeywords string
|
||||
PhotoColors string
|
||||
PhotoVibrantColor string
|
||||
PhotoMutedColor string
|
||||
PhotoCanonicalName string
|
||||
PhotoPerceptualHash string
|
||||
PhotoLat float64
|
||||
PhotoLong float64
|
||||
PhotoFavorite bool
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt time.Time
|
||||
TakenAt time.Time
|
||||
PhotoTitle string
|
||||
PhotoDescription string
|
||||
PhotoArtist string
|
||||
PhotoKeywords string
|
||||
PhotoColors string
|
||||
PhotoVibrantColor string
|
||||
PhotoMutedColor string
|
||||
PhotoCanonicalName string
|
||||
PhotoLat float64
|
||||
PhotoLong float64
|
||||
PhotoFavorite bool
|
||||
|
||||
// Camera
|
||||
CameraID uint
|
||||
|
@ -65,15 +64,18 @@ type PhotoSearchResult struct {
|
|||
LocType string
|
||||
|
||||
// File
|
||||
FileID uint
|
||||
FileName string
|
||||
FileHash string
|
||||
FileType string
|
||||
FileMime string
|
||||
FileWidth int
|
||||
FileHeight int
|
||||
FileOrientation int
|
||||
FileAspectRatio float64
|
||||
FileID uint
|
||||
FilePrimary bool
|
||||
FileMissing bool
|
||||
FileName string
|
||||
FileHash string
|
||||
FilePerceptualHash string
|
||||
FileType string
|
||||
FileMime string
|
||||
FileWidth int
|
||||
FileHeight int
|
||||
FileOrientation int
|
||||
FileAspectRatio float64
|
||||
|
||||
// Tags
|
||||
Tags string
|
||||
|
@ -92,7 +94,7 @@ func (s *Search) Photos(form PhotoSearchForm) ([]PhotoSearchResult, error) {
|
|||
q := s.db.NewScope(nil).DB()
|
||||
q = q.Table("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,
|
||||
lenses.lens_make, lenses.lens_model,
|
||||
countries.country_name,
|
||||
|
|
|
@ -21,4 +21,4 @@ func Start(conf *photoprism.Config) {
|
|||
registerRoutes(app, conf)
|
||||
|
||||
app.Run(fmt.Sprintf("%s:%d", conf.ServerIP, conf.ServerPort))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue