From caef6c096ca04b0a6631657491f1a9644c74746b Mon Sep 17 00:00:00 2001 From: mkelvers Date: Sun, 26 Apr 2026 20:38:09 +0200 Subject: [PATCH] feat: stay in fullscreen when transitioning to next episode --- api/playback/handler.go | 69 +++++++-------------------------------- internal/server/routes.go | 1 + static/player.ts | 12 +++++++ 3 files changed, 25 insertions(+), 57 deletions(-) diff --git a/api/playback/handler.go b/api/playback/handler.go index 7e6ea5e..a4053e6 100644 --- a/api/playback/handler.go +++ b/api/playback/handler.go @@ -280,52 +280,7 @@ func (h *Handler) HandleSaveProgress(w http.ResponseWriter, r *http.Request) { return } - w.WriteHeader(http.StatusNoContent) -} - -func (h *Handler) HandleCompleteAnime(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodPost { - http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) - return - } - - user := middleware.GetUser(r.Context()) - if user == nil { - http.Error(w, "Unauthorized", http.StatusUnauthorized) - return - } - - type completeAnimeRequest struct { - MalID int `json:"mal_id"` - Episode int `json:"episode"` - } - - var payload completeAnimeRequest - if err := json.NewDecoder(r.Body).Decode(&payload); err != nil { - http.Error(w, "invalid payload", http.StatusBadRequest) - return - } - - if payload.MalID <= 0 || payload.Episode <= 0 { - http.Error(w, "invalid payload", http.StatusBadRequest) - return - } - - animeID := int64(payload.MalID) - animeSeed, err := h.ensureAnimeSeed(r.Context(), payload.MalID) - if err != nil { - log.Printf("complete anime failed to resolve anime user_id=%s mal_id=%d err=%v", user.ID, payload.MalID, err) - http.Error(w, "failed to mark anime completed", http.StatusInternalServerError) - return - } - - if err := h.svc.CompleteAnime(r.Context(), user.ID, animeID, payload.Episode, animeSeed); err != nil { - log.Printf("complete anime failed user_id=%s mal_id=%d err=%v", user.ID, payload.MalID, err) - http.Error(w, "failed to mark anime completed", http.StatusInternalServerError) - return - } - - w.WriteHeader(http.StatusNoContent) +w.WriteHeader(http.StatusNoContent) } // HandleEpisodeData returns JSON for episode data (for in-player transitions) @@ -389,20 +344,20 @@ func (h *Handler) HandleEpisodeData(w http.ResponseWriter, r *http.Request) { } response := struct { - MalID int `json:"mal_id"` - Title string `json:"title"` - CurrentEpisode string `json:"current_episode"` - TotalEpisodes int `json:"total_episodes"` - InitialMode string `json:"initial_mode"` - Token string `json:"token"` - AvailableModes []string `json:"available_modes"` - ModeSources map[string]shared.ModeSource `json:"mode_sources"` - Segments []shared.SkipSegment `json:"segments"` + MalID int `json:"mal_id"` + Title string `json:"title"` + CurrentEpisode string `json:"current_episode"` + TotalEpisodes int `json:"total_episodes"` + InitialMode string `json:"initial_mode"` + Token string `json:"token"` + AvailableModes []string `json:"available_modes"` + ModeSources map[string]shared.ModeSource `json:"mode_sources"` + Segments []shared.SkipSegment `json:"segments"` }{ - MalID: malID, + MalID: malID, Title: data.Title, CurrentEpisode: data.CurrentEpisode, - TotalEpisodes: anime.Episodes, + TotalEpisodes: anime.Episodes, InitialMode: initialMode, Token: token, AvailableModes: data.AvailableModes, diff --git a/internal/server/routes.go b/internal/server/routes.go index 9c10dca..cace500 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -82,6 +82,7 @@ func NewRouter(cfg Config) http.Handler { mux.HandleFunc("/api/watch-progress", playbackHandler.HandleSaveProgress) mux.HandleFunc("/api/watch-complete", playbackHandler.HandleCompleteAnime) mux.HandleFunc("/api/watch/episode/", playbackHandler.HandleEpisodeData) + mux.HandleFunc("/api/watch/episode/", playbackHandler.HandleEpisodeData) // Auth Endpoints mux.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) { diff --git a/static/player.ts b/static/player.ts index 44cb6f8..2f4ae2a 100644 --- a/static/player.ts +++ b/static/player.ts @@ -32,6 +32,18 @@ interface EpisodeData { segments: SkipSegment[] } +interface EpisodeData { + mal_id: number + title: string + current_episode: string + total_episodes: number + initial_mode: string + token: string + available_modes: string[] + mode_sources: Record + segments: SkipSegment[] +} + let playerInitialized = false const initPlayer = (): void => {