diff --git a/internal/playback/handler/playlist_rewrite_test.go b/internal/playback/handler/playlist_rewrite_test.go index 73a6c209..1430f5f7 100644 --- a/internal/playback/handler/playlist_rewrite_test.go +++ b/internal/playback/handler/playlist_rewrite_test.go @@ -10,7 +10,8 @@ import ( ) type rewritePlaybackService struct { - targets []string + targets []string + targetURL string } func (s *rewritePlaybackService) BuildWatchData(context.Context, int, []string, string, string, string) (domain.WatchPageData, error) { @@ -31,7 +32,7 @@ func (s *rewritePlaybackService) SignProxyToken(targetURL, _ string, _ string) ( } func (s *rewritePlaybackService) ResolveProxyToken(string, string) (string, string, error) { - return "", "", nil + return s.targetURL, "", nil } func (s *rewritePlaybackService) UpsertSkipSegmentOverride(context.Context, string, int64, int, string, float64, float64) error { diff --git a/internal/playback/handler/watch_page_test.go b/internal/playback/handler/watch_page_test.go index 4e1afbea..071f25f3 100644 --- a/internal/playback/handler/watch_page_test.go +++ b/internal/playback/handler/watch_page_test.go @@ -17,14 +17,39 @@ import ( type watchPagePlaybackService struct { domain.PlaybackService - data domain.WatchPageData - err error + data domain.WatchPageData + err error + refreshRequested bool } -func (s *watchPagePlaybackService) BuildWatchData(context.Context, int, []string, string, string, string) (domain.WatchPageData, error) { +func (s *watchPagePlaybackService) BuildWatchData(ctx context.Context, _ int, _ []string, _ string, _ string, _ string) (domain.WatchPageData, error) { + s.refreshRequested = domain.PlaybackSourceRefreshRequested(ctx) return s.data, s.err } +func TestHandleEpisodeDataRequestsForcedSourceRefresh(t *testing.T) { + data := baseWatchPageData() + data.WatchData.ModeSources = map[string]domain.ModeSource{ + "sub": {Token: "opaque", Type: "m3u8"}, + } + svc := &watchPagePlaybackService{data: data} + h := &PlaybackHandler{svc: svc} + gin.SetMode(gin.TestMode) + router := gin.New() + router.GET("/api/watch/episode/:animeId/:episode", h.HandleEpisodeData) + + req := httptest.NewRequestWithContext(context.Background(), http.MethodGet, "/api/watch/episode/123/1?mode=sub&refresh=1", nil) + rec := httptest.NewRecorder() + router.ServeHTTP(rec, req) + + if rec.Code != http.StatusOK { + t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK) + } + if !svc.refreshRequested { + t.Fatal("episode handler did not request a forced source refresh") + } +} + type watchPageAnimeService struct { domain.AnimePlaybackService t *testing.T