From e5c5cde9740180184446de745623a3eabb470676 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Thu, 4 Mar 2021 10:52:45 +1100 Subject: [PATCH] Detect cover images in subdirectories (#1144) --- pkg/image/image.go | 2 +- pkg/image/image_test.go | 34 +++++++++++++++++++ .../src/components/Changelog/versions/v060.md | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 pkg/image/image_test.go diff --git a/pkg/image/image.go b/pkg/image/image.go index f11579a0f..d54271d66 100644 --- a/pkg/image/image.go +++ b/pkg/image/image.go @@ -246,7 +246,7 @@ func Serve(w http.ResponseWriter, r *http.Request, path string) { func IsCover(img *models.Image) bool { _, fn := getFilePath(img.Path) - return fn == "cover.jpg" + return strings.HasSuffix(fn, "cover.jpg") } func GetTitle(s *models.Image) string { diff --git a/pkg/image/image_test.go b/pkg/image/image_test.go new file mode 100644 index 000000000..3188a63d5 --- /dev/null +++ b/pkg/image/image_test.go @@ -0,0 +1,34 @@ +package image + +import ( + "fmt" + "path/filepath" + "testing" + + "github.com/stashapp/stash/pkg/models" + "github.com/stretchr/testify/assert" +) + +func TestIsCover(t *testing.T) { + type test struct { + fn string + isCover bool + } + + tests := []test{ + {"cover.jpg", true}, + {"covernot.jpg", false}, + {"Cover.jpg", false}, + {fmt.Sprintf("subDir%scover.jpg", string(filepath.Separator)), true}, + {"endsWithcover.jpg", true}, + {"cover.png", false}, + } + + assert := assert.New(t) + for _, tc := range tests { + img := &models.Image{ + Path: tc.fn, + } + assert.Equal(tc.isCover, IsCover(img), "expected: %t for %s", tc.isCover, tc.fn) + } +} diff --git a/ui/v2.5/src/components/Changelog/versions/v060.md b/ui/v2.5/src/components/Changelog/versions/v060.md index f1eda611e..5a333b2ce 100644 --- a/ui/v2.5/src/components/Changelog/versions/v060.md +++ b/ui/v2.5/src/components/Changelog/versions/v060.md @@ -10,6 +10,7 @@ * Added Rescan button to scene, image, gallery details overflow button. ### 🐛 Bug fixes +* Fix `cover.jpg` not being detected as cover image when in sub-directory. * Fix scan re-associating galleries to the same scene. * Fix SQL error when filtering galleries excluding performers or tags. * Fix version checking for armv7 and arm64.