diff --git a/package-lock.json b/package-lock.json index 14043f2..039ea34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6076,9 +6076,9 @@ } }, "node_modules/terser": { - "version": "5.51.2", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.51.2.tgz", - "integrity": "sha512-bWnjSNscmuI+GJze6ZupnHP8G/cTcsJF+bXCeQknk2SHQsgbNJnLrqiH9jZ2W4STPVXH2mDKKRX3iwPhc9Cn/Q==", + "version": "5.51.4", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.51.4.tgz", + "integrity": "sha512-VPi1CkDvCWLGUVIToctNBG+NdHbSXwOPjHJnQ3pdB0XknaldnI76wSkAFOGxV2ZdkzOP5d6gpQ5c58XvDghRvw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { diff --git a/src/components/RecapEntry.tsx b/src/components/RecapEntry.tsx index 3d961c7..9f98092 100644 --- a/src/components/RecapEntry.tsx +++ b/src/components/RecapEntry.tsx @@ -1,7 +1,7 @@ import { Sparkles, X } from 'lucide-react' import { lazy, Suspense, useMemo, useState } from 'react' import { t } from '../i18n' -import { recapSeasonYear, yearRecap } from '../lib/recap' +import { finishedInYear, recapSeasonYear, yearRecap } from '../lib/recap' import type { MediaItem } from '../types' // Les pages du bilan ne sont chargées qu'à l'ouverture @@ -20,7 +20,7 @@ function RecapViewer({ items, year, onClose, onSeeStats }: { items: MediaItem[]; /** Bouton « Mon année 2026 » de la page Stats (si l'année a au moins un titre terminé). */ export function RecapButton({ items, year }: { items: MediaItem[]; year: string }) { const [open, setOpen] = useState(false) - const finished = useMemo(() => yearRecap(items, year).finished, [items, year]) + const finished = useMemo(() => finishedInYear(items, year), [items, year]) if (!finished) return null return ( <> @@ -41,7 +41,7 @@ const hiddenKey = (year: string) => `azuucine:recap-hint-${year}` */ export function RecapHint({ items, onSeeStats }: { items: MediaItem[]; onSeeStats: () => void }) { const year = recapSeasonYear() - const finished = useMemo(() => (year ? yearRecap(items, year).finished : 0), [items, year]) + const finished = useMemo(() => (year ? finishedInYear(items, year) : 0), [items, year]) const [hidden, setHidden] = useState(() => { try { return !!year && localStorage.getItem(hiddenKey(year)) === '1' diff --git a/src/components/YearRecap.tsx b/src/components/YearRecap.tsx index f245a60..7b20ade 100644 --- a/src/components/YearRecap.tsx +++ b/src/components/YearRecap.tsx @@ -174,6 +174,8 @@ export default function YearRecap({ recap, onClose, onSeeStats }: { recap: Recap const go = (d: number) => setPage((p) => Math.min(last, Math.max(0, p + d))) useEffect(() => { + // Aperçu de l'image ouvert par-dessus : les flèches ne tournent pas les pages derrière + if (share) return const onKey = (e: KeyboardEvent) => { if (e.key === 'ArrowRight') go(document.dir === 'rtl' ? -1 : 1) else if (e.key === 'ArrowLeft') go(document.dir === 'rtl' ? 1 : -1) @@ -181,7 +183,7 @@ export default function YearRecap({ recap, onClose, onSeeStats }: { recap: Recap window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [last]) + }, [last, share]) async function makeShare() { setBusy(true) diff --git a/src/lib/catalogApi.ts b/src/lib/catalogApi.ts index 4a71f76..f17be5e 100644 --- a/src/lib/catalogApi.ts +++ b/src/lib/catalogApi.ts @@ -149,7 +149,7 @@ async function tmdbFetch(path: string, key: string, params: Record } @@ -336,6 +336,8 @@ export interface EpisodeInfo { // de la fiche, puis est rafraîchie en arrière-plan si elle date de plus de 12 h (nouveaux épisodes, images) const SEASONS_KEY = 'azuucine:seasons' const SEASONS_FRESH = 12 * 3600_000 +/** Saison introuvable chez TMDB (annoncée mais pas encore créée) : on ne la redemande pas avant 3 h. */ +const SEASON_MISSING_FOR = 3 * 3600_000 const SEASONS_MAX_AGE = 30 * 24 * 3600_000 const SEASONS_BUDGET = 400_000 type SeasonEntry = { at: number; eps: EpisodeInfo[] } @@ -428,6 +430,13 @@ export async function getTmdbSeasonEpisodes(externalId: string, season: number, saveSeasons() return list }) + .catch((e: unknown) => { + if ((e as { status?: number })?.status !== 404) throw e + // Gardée comme une saison vide, « périmée » au bout de 3 h au lieu de 12 (elle peut arriver bientôt) + seasonsStore().set(cacheKey, { at: Date.now() - SEASONS_FRESH + SEASON_MISSING_FOR, eps: [] }) + saveSeasons() + return [] as EpisodeInfo[] + }) .finally(() => seasonsInflight.delete(cacheKey)) seasonsInflight.set(cacheKey, p) } @@ -884,7 +893,8 @@ function sharedTmdb(path: string, key: string): Promise { job = tmdbFetch(path, key) showJobs.set(id, job) const forget = () => setTimeout(() => showJobs.delete(id), 10 * 60_000) - job.then(forget, () => showJobs.delete(id)) + // Une saison introuvable (404) n'est pas redemandée pendant 10 min ; une autre erreur, oui (réseau…) + job.then(forget, (e: unknown) => ((e as { status?: number })?.status === 404 ? forget() : showJobs.delete(id))) } return job } diff --git a/src/lib/cloud/api.ts b/src/lib/cloud/api.ts index 65c4977..ccc61a6 100644 --- a/src/lib/cloud/api.ts +++ b/src/lib/cloud/api.ts @@ -63,7 +63,8 @@ export async function tmdbViaCloud(path: string, params: Record } diff --git a/src/lib/recap.ts b/src/lib/recap.ts index b10ec56..4fac917 100644 --- a/src/lib/recap.ts +++ b/src/lib/recap.ts @@ -61,6 +61,11 @@ export function yearRecap(items: MediaItem[], year: string): YearRecap { } } +/** Titres terminés dans l'année : de quoi décider d'afficher le bilan, sans tout calculer. */ +export function finishedInYear(items: MediaItem[], year: string): number { + return itemsForPeriod(items, year).filter((i) => i.status === 'termine').length +} + /** * Année dont le bilan est mis en avant sur l'accueil : l'année en cours en décembre, l'année passée en janvier. * Le reste du temps, aucun (le bilan reste accessible depuis les stats).