From a252d16bf4f3d56f144e336a7efec0b77beba447 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Tue, 30 Jan 2024 20:12:29 +0800 Subject: [PATCH] Fix: ali cache nil pointer --- internal/op/movies.go | 3 +++ internal/op/room.go | 3 +++ server/handlers/movie.go | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/op/movies.go b/internal/op/movies.go index ed8716f..9c9845c 100644 --- a/internal/op/movies.go +++ b/internal/op/movies.go @@ -169,6 +169,9 @@ func (m *movies) GetMovieByID(id string) (*Movie, error) { } func (m *movies) getMovieByID(id string) (*Movie, error) { + if id == "" { + return nil, errors.New("movie id is nil") + } m.init() for e := m.list.Front(); e != nil; e = e.Next() { if e.Value.Movie.ID == id { diff --git a/internal/op/room.go b/internal/op/room.go index 6d37c5e..da448b4 100644 --- a/internal/op/room.go +++ b/internal/op/room.go @@ -181,6 +181,9 @@ func (r *Room) Current() *Current { } func (r *Room) CurrentMovie() (*Movie, error) { + if r.current.current.Movie.ID == "" { + return nil, errors.New("no current movie") + } return r.GetMovieByID(r.current.current.Movie.ID) } diff --git a/server/handlers/movie.go b/server/handlers/movie.go index f4a01d5..6b95c37 100644 --- a/server/handlers/movie.go +++ b/server/handlers/movie.go @@ -87,7 +87,7 @@ func genCurrentRespWithCurrent(ctx context.Context, user *op.User, room *op.Room } opMovie, err := room.GetMovieByID(current.Movie.ID) if err != nil { - return nil, err + return nil, fmt.Errorf("get current movie error: %w", err) } var movie = opMovie.Movie if movie.Base.VendorInfo.Vendor != "" { @@ -1042,7 +1042,7 @@ func genVendorMovie(ctx context.Context, user *op.User, opMovie *op.Movie) (*dbM return nil, err } - if len(data.Ali.M3U8ListFile) != 0 { + if data.Ali != nil { rawPath, err := url.JoinPath("/api/movie/proxy", movie.RoomID, movie.ID) if err != nil { return nil, err