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)
|
app.Run(os.Args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
@ -28,4 +28,4 @@ func GetPhotos (router *gin.RouterGroup, conf *photoprism.Config) {
|
||||||
|
|
||||||
c.JSON(http.StatusOK, result)
|
c.JSON(http.StatusOK, result)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var ExportCommand = cli.Command{
|
var ExportCommand = cli.Command{
|
||||||
Name: "export",
|
Name: "export",
|
||||||
Usage: "Exports photos as JPEG",
|
Usage: "Exports photos as JPEG",
|
||||||
Flags: exportFlags,
|
Flags: exportFlags,
|
||||||
Action: exportAction,
|
Action: exportAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var MigrateCommand = cli.Command{
|
var MigrateCommand = cli.Command{
|
||||||
Name: "migrate",
|
Name: "migrate",
|
||||||
Usage: "Automatically migrates / initializes database",
|
Usage: "Automatically migrates / initializes database",
|
||||||
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...")
|
||||||
|
|
|
@ -8,8 +8,8 @@ type Album struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
AlbumSlug string
|
AlbumSlug string
|
||||||
AlbumName string
|
AlbumName string
|
||||||
AlbumDescription string `gorm:"type:text;"`
|
AlbumDescription string `gorm:"type:text;"`
|
||||||
AlbumNotes string `gorm:"type:text;"`
|
AlbumNotes string `gorm:"type:text;"`
|
||||||
AlbumPhoto *Photo
|
AlbumPhoto *Photo
|
||||||
AlbumPhotoID uint
|
AlbumPhotoID uint
|
||||||
Photos []Photo `gorm:"many2many:album_photos;"`
|
Photos []Photo `gorm:"many2many:album_photos;"`
|
||||||
|
|
|
@ -6,16 +6,19 @@ import (
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Photo *Photo
|
Photo *Photo
|
||||||
PhotoID uint
|
PhotoID uint
|
||||||
FilePrimary bool
|
FilePrimary bool
|
||||||
FileName string
|
FileMissing bool
|
||||||
FileType string `gorm:"type:varchar(30)"`
|
FileName string
|
||||||
FileMime string `gorm:"type:varchar(50)"`
|
FileType string `gorm:"type:varchar(30)"`
|
||||||
FileWidth int
|
FileMime string `gorm:"type:varchar(50)"`
|
||||||
FileHeight int
|
FileWidth int
|
||||||
FileOrientation int
|
FileHeight int
|
||||||
FileAspectRatio float64
|
FileOrientation int
|
||||||
FileHash string `gorm:"type:varchar(100);unique_index"`
|
FileAspectRatio float64
|
||||||
FileNotes string `gorm:"type:text;"`
|
FileHash string `gorm:"type:varchar(100);unique_index"`
|
||||||
|
FilePerceptualHash string
|
||||||
|
|
||||||
|
FileNotes string `gorm:"type:text;"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,33 +7,32 @@ import (
|
||||||
|
|
||||||
type Photo struct {
|
type Photo struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
TakenAt time.Time
|
TakenAt time.Time
|
||||||
PhotoTitle string
|
PhotoTitle string
|
||||||
PhotoTitleChanged bool
|
PhotoTitleChanged bool
|
||||||
PhotoDescription string `gorm:"type:text;"`
|
PhotoDescription string `gorm:"type:text;"`
|
||||||
PhotoNotes string `gorm:"type:text;"`
|
PhotoNotes string `gorm:"type:text;"`
|
||||||
PhotoArtist string
|
PhotoArtist string
|
||||||
PhotoColors string
|
PhotoColors string
|
||||||
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
|
PhotoFocalLength float64
|
||||||
PhotoFocalLength float64
|
PhotoAperture float64
|
||||||
PhotoAperture float64
|
Camera *Camera
|
||||||
Camera *Camera
|
CameraID uint
|
||||||
CameraID uint
|
Lens *Lens
|
||||||
Lens *Lens
|
LensID uint
|
||||||
LensID uint
|
Country *Country
|
||||||
Country *Country
|
CountryID string
|
||||||
CountryID string
|
CountryChanged bool
|
||||||
CountryChanged bool
|
Location *Location
|
||||||
Location *Location
|
LocationID uint
|
||||||
LocationID uint
|
LocationChanged bool
|
||||||
LocationChanged bool
|
Tags []*Tag `gorm:"many2many:photo_tags;"`
|
||||||
Tags []*Tag `gorm:"many2many:photo_tags;"`
|
Files []*File
|
||||||
Files []*File
|
Albums []*Album `gorm:"many2many:album_photos;"`
|
||||||
Albums []*Album `gorm:"many2many:album_photos;"`
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -19,23 +19,22 @@ type SearchCount struct {
|
||||||
|
|
||||||
type PhotoSearchResult struct {
|
type PhotoSearchResult struct {
|
||||||
// Photo
|
// Photo
|
||||||
ID uint
|
ID uint
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
DeletedAt time.Time
|
DeletedAt time.Time
|
||||||
TakenAt time.Time
|
TakenAt time.Time
|
||||||
PhotoTitle string
|
PhotoTitle string
|
||||||
PhotoDescription string
|
PhotoDescription string
|
||||||
PhotoArtist string
|
PhotoArtist string
|
||||||
PhotoKeywords string
|
PhotoKeywords string
|
||||||
PhotoColors string
|
PhotoColors string
|
||||||
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
|
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
CameraID uint
|
CameraID uint
|
||||||
|
@ -65,15 +64,18 @@ type PhotoSearchResult struct {
|
||||||
LocType string
|
LocType string
|
||||||
|
|
||||||
// File
|
// File
|
||||||
FileID uint
|
FileID uint
|
||||||
FileName string
|
FilePrimary bool
|
||||||
FileHash string
|
FileMissing bool
|
||||||
FileType string
|
FileName string
|
||||||
FileMime string
|
FileHash string
|
||||||
FileWidth int
|
FilePerceptualHash string
|
||||||
FileHeight int
|
FileType string
|
||||||
FileOrientation int
|
FileMime string
|
||||||
FileAspectRatio float64
|
FileWidth int
|
||||||
|
FileHeight int
|
||||||
|
FileOrientation int
|
||||||
|
FileAspectRatio float64
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
Tags string
|
Tags string
|
||||||
|
@ -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,
|
||||||
|
|
|
@ -21,4 +21,4 @@ func Start(conf *photoprism.Config) {
|
||||||
registerRoutes(app, conf)
|
registerRoutes(app, conf)
|
||||||
|
|
||||||
app.Run(fmt.Sprintf("%s:%d", conf.ServerIP, conf.ServerPort))
|
app.Run(fmt.Sprintf("%s:%d", conf.ServerIP, conf.ServerPort))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue