From 379c46df640ff4bee2a00addc478d0f340dfe2ff Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Mon, 6 Jul 2020 19:50:01 +0200 Subject: [PATCH] Backend: Return error if no main file for indexing was found #379 #357 Signed-off-by: Michael Mayer --- internal/photoprism/mediafile.go | 6 +++++- internal/photoprism/related.go | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/photoprism/mediafile.go b/internal/photoprism/mediafile.go index 494476a9e..ce12fc7ef 100644 --- a/internal/photoprism/mediafile.go +++ b/internal/photoprism/mediafile.go @@ -288,8 +288,12 @@ func (m *MediaFile) RelatedFiles(stripSequence bool) (result RelatedFiles, err e result.Files = append(result.Files, resultFile) } + if result.Main == nil { + return result, fmt.Errorf("no main file found for %s", txt.Quote(m.BaseName())) + } + // Add hidden JPEG if exists. - if !result.ContainsJpeg() && result.Main != nil { + if !result.ContainsJpeg() { if jpegName := fs.TypeJpeg.FindFirst(result.Main.FileName(), []string{Config().SidecarPath(), fs.HiddenPath}, Config().OriginalsPath(), stripSequence); jpegName != "" { if resultFile, err := NewMediaFile(jpegName); err == nil { result.Files = append(result.Files, resultFile) diff --git a/internal/photoprism/related.go b/internal/photoprism/related.go index eb8308a3c..d6b591516 100644 --- a/internal/photoprism/related.go +++ b/internal/photoprism/related.go @@ -8,15 +8,15 @@ type RelatedFiles struct { // ContainsJpeg returns true if related file list contains a JPEG. func (rf RelatedFiles) ContainsJpeg() bool { - if rf.Main.IsJpeg() { - return true - } - for _, f := range rf.Files { if f.IsJpeg() { return true } } - return false + if rf.Main == nil { + return false + } + + return rf.Main.IsJpeg() }