mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 11:36:36 +08:00
fix: load full poster wall media
This commit is contained in:
@@ -198,8 +198,10 @@ func (s *MediaService) SearchMedia(ctx context.Context, query string, limit int)
|
||||
}
|
||||
|
||||
func (s *MediaService) SearchMediaVisible(ctx context.Context, query string, limit int, visibility MediaVisibility) ([]model.Media, error) {
|
||||
if limit <= 0 || limit > 200 {
|
||||
if limit <= 0 {
|
||||
limit = 50
|
||||
} else if limit > 2000 {
|
||||
limit = 2000
|
||||
}
|
||||
return s.repo.Media.SearchFiltered(ctx, query, limit, repository.MediaQueryFilter{
|
||||
IncludeNSFW: visibility.IncludeNSFW,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
@@ -140,6 +141,41 @@ func TestConfiguredAdultLibrariesDoNotHideSafeLibraryWithNSFWItems(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchMediaVisibleHonorsLargePosterWallLimit(t *testing.T) {
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.AutoMigrate(&model.Library{}, &model.Media{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
repos := repository.New(db)
|
||||
lib := model.Library{Name: "海报墙", Path: "/media/all", Type: "tv", Enabled: true}
|
||||
if err := repos.Library.Create(t.Context(), &lib); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows := make([]model.Media, 260)
|
||||
for i := range rows {
|
||||
rows[i] = model.Media{
|
||||
LibraryID: lib.ID,
|
||||
Title: fmt.Sprintf("节目 %03d", i),
|
||||
Path: fmt.Sprintf("/media/all/show-%03d.mkv", i),
|
||||
}
|
||||
}
|
||||
if err := db.Create(&rows).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
items, err := NewMediaService(&config.Config{}, zap.NewNop(), repos).
|
||||
SearchMediaVisible(t.Context(), "", 240, MediaVisibility{IncludeNSFW: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(items) != 240 {
|
||||
t.Fatalf("large poster wall search returned %d rows, want 240", len(items))
|
||||
}
|
||||
}
|
||||
|
||||
func sortedMediaTitles(rows []model.Media) []string {
|
||||
out := make([]string, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
|
||||
Reference in New Issue
Block a user