diff --git a/api/anime/handler.go b/api/anime/handler.go index 2b11d99..4309978 100644 --- a/api/anime/handler.go +++ b/api/anime/handler.go @@ -265,6 +265,9 @@ func (h *Handler) HandleAPIAnime(w http.ResponseWriter, r *http.Request) { } statuses := h.watchlistMap(r.Context(), userIDFromRequest(r)) + + w.Header().Set("Cache-Control", "public, max-age=3600") + switch section { case "relations": relations, err := h.jikanClient.GetFullRelations(r.Context(), id) @@ -313,15 +316,14 @@ func (h *Handler) HandleAPIAnime(w http.ResponseWriter, r *http.Request) { func (h *Handler) HandleAPIEpisodes(w http.ResponseWriter, r *http.Request) { path := r.URL.Path[len("/api/episodes/"):] - path = strings.Trim(path, "/") - id, err := strconv.Atoi(path) if err != nil || id <= 0 { http.Error(w, "invalid id", http.StatusBadRequest) return } - currentEpisode := r.URL.Query().Get("current") + w.Header().Set("Cache-Control", "public, max-age=3600") + episodes, err := h.getEpisodes(r.Context(), id) if err != nil { log.Printf("episodes error: %v", err) diff --git a/api/playback/handler.go b/api/playback/handler.go index 9a75bb5..7e6ea5e 100644 --- a/api/playback/handler.go +++ b/api/playback/handler.go @@ -388,21 +388,21 @@ func (h *Handler) HandleEpisodeData(w http.ResponseWriter, r *http.Request) { token = source.Token } -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"` + 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: 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/pkg/middleware/logging.go b/pkg/middleware/logging.go index fd73ea4..cc96813 100644 --- a/pkg/middleware/logging.go +++ b/pkg/middleware/logging.go @@ -69,8 +69,10 @@ func RequestLogger(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { start := time.Now() - if strings.HasPrefix(r.URL.Path, "/dist/static/") || + if strings.HasPrefix(r.URL.Path, "/dist/") || strings.HasPrefix(r.URL.Path, "/static/") || + strings.HasPrefix(r.URL.Path, "/watch/proxy/stream") || + strings.HasPrefix(r.URL.Path, "/watch/proxy/segment") || r.URL.Path == "/favicon.ico" { next.ServeHTTP(w, r) return diff --git a/static/player.ts b/static/player.ts index 1541b19..44cb6f8 100644 --- a/static/player.ts +++ b/static/player.ts @@ -404,7 +404,7 @@ const initPlayer = (): void => { if (!Number.isInteger(episodeNumber) || episodeNumber <= 0) return const safeTime = displayTimeFromAbsolute(video.currentTime) - if (lastSavedProgress.episode === currentEpisode && Math.abs(lastSavedProgress.seconds - safeTime) < 2) { + if (lastSavedProgress.episode === currentEpisode && Math.abs(lastSavedProgress.seconds - safeTime) < 5) { return } @@ -433,7 +433,7 @@ const initPlayer = (): void => { progressSaveTimer = window.setTimeout(() => { progressSaveTimer = undefined saveProgress() - }, 1500) + }, 30000) } const parseEpisodeFromWatchHref = (href: string): number | null => {