From 13fe9af2fc34a7b6916ae38cc114b0ea4f3e5c11 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 17 Jul 2020 10:10:01 +0200 Subject: [PATCH] Backend: Fix panorama detection #352 Signed-off-by: Michael Mayer --- internal/entity/file.go | 2 +- internal/entity/file_test.go | 10 +++++++++- internal/photoprism/index_mediafile.go | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/entity/file.go b/internal/entity/file.go index 70afdf07a..e66dfff95 100644 --- a/internal/entity/file.go +++ b/internal/entity/file.go @@ -226,5 +226,5 @@ func (m *File) Panorama() bool { return false } - return m.FileProjection != ProjectionDefault || m.FileWidth/m.FileHeight > 2 + return m.FileProjection != ProjectionDefault || (m.FileWidth/m.FileHeight) >= 2 } diff --git a/internal/entity/file_test.go b/internal/entity/file_test.go index cba7f41f8..82feca101 100644 --- a/internal/entity/file_test.go +++ b/internal/entity/file_test.go @@ -234,10 +234,18 @@ func TestFile_NoJPEG(t *testing.T) { } func TestFile_Panorama(t *testing.T) { - t.Run("true", func(t *testing.T) { + t.Run("3000", func(t *testing.T) { file := &File{Photo: nil, FileType: "jpg", FileSidecar: false, FileWidth: 3000, FileHeight: 1000} assert.True(t, file.Panorama()) }) + t.Run("1999", func(t *testing.T) { + file := &File{Photo: nil, FileType: "jpg", FileSidecar: false, FileWidth: 1999, FileHeight: 1000} + assert.False(t, file.Panorama()) + }) + t.Run("2000", func(t *testing.T) { + file := &File{Photo: nil, FileType: "jpg", FileSidecar: false, FileWidth: 2000, FileHeight: 1000} + assert.True(t, file.Panorama()) + }) t.Run("false", func(t *testing.T) { file := &File{Photo: nil, FileType: "jpg", FileSidecar: false, FileWidth: 1500, FileHeight: 1000} assert.False(t, file.Panorama()) diff --git a/internal/photoprism/index_mediafile.go b/internal/photoprism/index_mediafile.go index 589d271a4..07b17397e 100644 --- a/internal/photoprism/index_mediafile.go +++ b/internal/photoprism/index_mediafile.go @@ -403,10 +403,6 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) ( file.FileMissing = false file.FileError = "" - if file.Panorama() { - photo.PhotoPanorama = true - } - // primary files are used for rendering thumbnails and image classification (plus sidecar files if they exist) if file.FilePrimary { primaryFile = file @@ -510,6 +506,10 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) ( photo.UpdateDateFields() + if file.Panorama() { + photo.PhotoPanorama = true + } + file.FileSidecar = m.IsSidecar() file.FileVideo = m.IsVideo() file.FileRoot = fileRoot