From bdab999f95ab762a2f53817d21fcdeb5cf7affb5 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Tue, 30 Jan 2024 18:57:44 +0800 Subject: [PATCH] Fix: gen current resp miss change movie filed --- internal/op/current.go | 9 +++++---- server/handlers/movie.go | 29 ++++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/internal/op/current.go b/internal/op/current.go index 2e087b3..fce87e7 100644 --- a/internal/op/current.go +++ b/internal/op/current.go @@ -43,7 +43,7 @@ func newStatus() Status { func (c *current) Current() Current { c.lock.RLock() defer c.lock.RUnlock() - c.current.UpdateSeek() + c.current.UpdateStatus() return c.current } @@ -63,7 +63,7 @@ func (c *current) SetMovie(movie *model.Movie, play bool) { func (c *current) Status() Status { c.lock.RLock() defer c.lock.RUnlock() - c.current.UpdateSeek() + c.current.UpdateStatus() return c.current.Status } @@ -81,15 +81,16 @@ func (c *current) SetSeekRate(seek, rate, timeDiff float64) Status { return c.current.SetSeekRate(seek, rate, timeDiff) } -func (c *Current) UpdateSeek() { +func (c *Current) UpdateStatus() Status { if c.Movie.Base.Live { c.Status.lastUpdate = time.Now() - return + return c.Status } if c.Status.Playing { c.Status.Seek += time.Since(c.Status.lastUpdate).Seconds() * c.Status.Rate } c.Status.lastUpdate = time.Now() + return c.Status } func (c *Current) setLiveStatus() Status { diff --git a/server/handlers/movie.go b/server/handlers/movie.go index 00fb87e..f4a01d5 100644 --- a/server/handlers/movie.go +++ b/server/handlers/movie.go @@ -89,33 +89,32 @@ func genCurrentRespWithCurrent(ctx context.Context, user *op.User, room *op.Room if err != nil { return nil, err } - var movie *dbModel.Movie = &opMovie.Movie - if current.Movie.Base.VendorInfo.Vendor != "" { + var movie = opMovie.Movie + if movie.Base.VendorInfo.Vendor != "" { vendorMovie, err := genVendorMovie(ctx, user, opMovie) if err != nil { return nil, err } - movie = vendorMovie - } else if current.Movie.Base.RtmpSource || current.Movie.Base.Live && current.Movie.Base.Proxy { - switch current.Movie.Base.Type { + movie = *vendorMovie + } else if movie.Base.RtmpSource || movie.Base.Live && movie.Base.Proxy { + switch movie.Base.Type { case "m3u8": - current.Movie.Base.Url = fmt.Sprintf("/api/movie/live/hls/list/%s.m3u8", current.Movie.ID) + movie.Base.Url = fmt.Sprintf("/api/movie/live/hls/list/%s.m3u8", movie.ID) case "flv": - current.Movie.Base.Url = fmt.Sprintf("/api/movie/live/flv/%s.flv", current.Movie.ID) + movie.Base.Url = fmt.Sprintf("/api/movie/live/flv/%s.flv", movie.ID) default: return nil, errors.New("not support live movie type") } - current.Movie.Base.Headers = nil - } else if current.Movie.Base.Proxy { - current.Movie.Base.Url = fmt.Sprintf("/api/movie/proxy/%s/%s", current.Movie.RoomID, current.Movie.ID) - current.Movie.Base.Headers = nil + movie.Base.Headers = nil + } else if movie.Base.Proxy { + movie.Base.Url = fmt.Sprintf("/api/movie/proxy/%s/%s", movie.RoomID, movie.ID) + movie.Base.Headers = nil } - if current.Movie.Base.Type == "" && current.Movie.Base.Url != "" { - current.Movie.Base.Type = utils.GetUrlExtension(current.Movie.Base.Url) + if movie.Base.Type == "" && movie.Base.Url != "" { + movie.Base.Type = utils.GetUrlExtension(movie.Base.Url) } - current.UpdateSeek() resp := &model.CurrentMovieResp{ - Status: current.Status, + Status: current.UpdateStatus(), Movie: model.MoviesResp{ Id: movie.ID, CreatedAt: movie.CreatedAt.UnixMilli(),