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

@@ -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)