fix: ensure segments is never nil in watch page data

This commit is contained in:
2026-05-02 16:47:26 +02:00
committed by Mikkel Elvers
parent 82350740c4
commit efcd34bcb7
2 changed files with 13 additions and 5 deletions

View File

@@ -313,7 +313,7 @@ func (h *Handler) HandleDiscover(w http.ResponseWriter, r *http.Request) {
seen[a.MalID] = true
uniqueTrending = append(uniqueTrending, a)
}
if len(uniqueTrending) >= 10 {
if len(uniqueTrending) >= 8 {
break
}
}
@@ -324,7 +324,7 @@ func (h *Handler) HandleDiscover(w http.ResponseWriter, r *http.Request) {
seen[a.MalID] = true
uniqueUpcoming = append(uniqueUpcoming, a)
}
if len(uniqueUpcoming) >= 10 {
if len(uniqueUpcoming) >= 8 {
break
}
}
@@ -335,7 +335,7 @@ func (h *Handler) HandleDiscover(w http.ResponseWriter, r *http.Request) {
seen[a.MalID] = true
uniqueTop = append(uniqueTop, a)
}
if len(uniqueTop) >= 10 {
if len(uniqueTop) >= 8 {
break
}
}

View File

@@ -169,6 +169,11 @@ func (s *Service) BuildWatchPageData(ctx context.Context, malID int, titleCandid
return WatchPageData{}, errors.New("stream mode unavailable")
}
segments := baseData.Segments
if segments == nil {
segments = []SkipSegment{}
}
userState := userPlaybackState{}
if userStateCh != nil {
userState = <-userStateCh
@@ -183,7 +188,7 @@ func (s *Service) BuildWatchPageData(ctx context.Context, malID int, titleCandid
InitialMode: initialMode,
AvailableModes: cloneSlice(baseData.AvailableModes),
ModeSources: clientModeSources,
Segments: cloneSlice(baseData.Segments),
Segments: cloneSlice(segments),
}, nil
}
@@ -345,8 +350,11 @@ func clonePlaybackBaseData(data playbackBaseData) playbackBaseData {
}
func cloneSlice[T any](items []T) []T {
if items == nil {
return []T{}
}
if len(items) == 0 {
return nil
return []T{}
}
cloned := make([]T, len(items))
copy(cloned, items)