Backend: Return error if no main file for indexing was found #379 #357

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-07-06 19:50:01 +02:00
parent eeef16f07e
commit 379c46df64
2 changed files with 10 additions and 6 deletions

View file

@ -288,8 +288,12 @@ func (m *MediaFile) RelatedFiles(stripSequence bool) (result RelatedFiles, err e
result.Files = append(result.Files, resultFile) 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. // 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 jpegName := fs.TypeJpeg.FindFirst(result.Main.FileName(), []string{Config().SidecarPath(), fs.HiddenPath}, Config().OriginalsPath(), stripSequence); jpegName != "" {
if resultFile, err := NewMediaFile(jpegName); err == nil { if resultFile, err := NewMediaFile(jpegName); err == nil {
result.Files = append(result.Files, resultFile) result.Files = append(result.Files, resultFile)

View file

@ -8,15 +8,15 @@ type RelatedFiles struct {
// ContainsJpeg returns true if related file list contains a JPEG. // ContainsJpeg returns true if related file list contains a JPEG.
func (rf RelatedFiles) ContainsJpeg() bool { func (rf RelatedFiles) ContainsJpeg() bool {
if rf.Main.IsJpeg() {
return true
}
for _, f := range rf.Files { for _, f := range rf.Files {
if f.IsJpeg() { if f.IsJpeg() {
return true return true
} }
} }
return false if rf.Main == nil {
return false
}
return rf.Main.IsJpeg()
} }