From 97d55b24a1c9c9cec0816beaf853ac0ab8826541 Mon Sep 17 00:00:00 2001 From: ner Date: Mon, 28 Oct 2024 20:04:36 +0200 Subject: [PATCH] refactoring: server actions => tmdb proxy --- app/api/tmdb/[...path]/route.ts | 32 ++++++++- components/Header/components/User/useAuth.ts | 13 +++- components/ui/badge.tsx | 35 ++++------ data/clients/Http.ts | 4 ++ data/clients/movieAdvisor.ts | 12 ++-- data/clients/theMovieDb.ts | 6 +- data/index.ts | 68 +++----------------- data/mutations/accountStates.ts | 28 ++++++++ data/queries/accountStates.ts | 16 +++++ env.ts | 3 + hooks/useShowState.ts | 20 ++---- hooks/useUsersShows.ts | 5 +- public/sw.js | 2 +- 13 files changed, 131 insertions(+), 113 deletions(-) create mode 100644 data/mutations/accountStates.ts create mode 100644 data/queries/accountStates.ts diff --git a/app/api/tmdb/[...path]/route.ts b/app/api/tmdb/[...path]/route.ts index eab169f..d0d129a 100644 --- a/app/api/tmdb/[...path]/route.ts +++ b/app/api/tmdb/[...path]/route.ts @@ -1,6 +1,6 @@ import { NextRequest, NextResponse } from 'next/server'; -import { MOVIE_DB_TOKEN } from '@/env'; +import { MOVIE_DB_API_URL, MOVIE_DB_TOKEN } from '@/env'; type TMDBParams = { params: { @@ -8,9 +8,9 @@ type TMDBParams = { }; }; -export async function GET({ nextUrl: { searchParams } }: NextRequest, { params: { path } }: TMDBParams) { +export async function GET({ nextUrl: { searchParams }, headers }: NextRequest, { params: { path } }: TMDBParams) { try { - const response = await fetch(`https://api.themoviedb.org/3/${path.join('/')}?${searchParams.toString()}`, { + const response = await fetch(`${MOVIE_DB_API_URL}/${path.join('/')}?${searchParams.toString()}`, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${MOVIE_DB_TOKEN}` @@ -28,3 +28,29 @@ export async function GET({ nextUrl: { searchParams } }: NextRequest, { params: return NextResponse.json({ error: 'An error occurred' }, { status: 500 }); } } + +export async function POST(request: NextRequest, { params: { path } }: TMDBParams) { + try { + const requestBody = await request.json(); + const searchParams = request.nextUrl.searchParams.toString(); + + const response = await fetch(`${MOVIE_DB_API_URL}/${path.join('/')}?${searchParams}`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${MOVIE_DB_TOKEN}` + }, + body: JSON.stringify(requestBody) + }); + + if (!response.ok) { + return NextResponse.json({ error: 'Failed to post data to TMDb' }, { status: response.status }); + } + + const data = await response.json(); + + return NextResponse.json(data); + } catch (error) { + return NextResponse.json({ error: 'An error occurred' }, { status: 500 }); + } +} diff --git a/components/Header/components/User/useAuth.ts b/components/Header/components/User/useAuth.ts index 43136b5..5ef0c1e 100644 --- a/components/Header/components/User/useAuth.ts +++ b/components/Header/components/User/useAuth.ts @@ -1,4 +1,4 @@ -import { useRef } from 'react'; +import { useEffect, useRef } from 'react'; import { useMutation } from '@tanstack/react-query'; import { useSetSession } from '@/hooks/useSession'; @@ -8,12 +8,19 @@ import { createRequestToken, createSession } from '../../../../data'; const useAuth = () => { const setSession = useSetSession(); const tabRef = useRef(null); + const intervalRef = useRef(); + + useEffect(() => { + const interval = intervalRef.current; + return () => clearInterval(interval); + }, []); const session = useMutation({ - retry: 5, mutationFn: createSession, onSuccess({ session_id }) { setSession(session_id); + clearInterval(intervalRef.current); + tabRef.current?.close(); } }); @@ -29,7 +36,7 @@ const useAuth = () => { tabRef.current.location = redirectUrl; - session.mutate({ requestToken }); + intervalRef.current = setInterval(() => session.mutate({ requestToken }), 2000); } }); diff --git a/components/ui/badge.tsx b/components/ui/badge.tsx index 0c0985c..d698f37 100644 --- a/components/ui/badge.tsx +++ b/components/ui/badge.tsx @@ -1,36 +1,29 @@ -import * as React from 'react' -import { cva, type VariantProps } from 'class-variance-authority' +import * as React from 'react'; +import { cva, type VariantProps } from 'class-variance-authority'; -import { cn } from '@/lib/utils' +import { cn } from '@/lib/utils'; const badgeVariants = cva( 'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2', { variants: { variant: { - default: - 'border-transparent bg-primary text-primary-foreground hover:bg-primary/80', - secondary: - 'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80', - destructive: - 'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80', - outline: 'text-foreground', - }, + default: 'border-transparent bg-primary text-primary-foreground hover:bg-primary/80', + secondary: 'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80', + destructive: 'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80', + outline: 'text-foreground' + } }, defaultVariants: { - variant: 'default', - }, + variant: 'default' + } } -) +); -export interface BadgeProps - extends React.HTMLAttributes, - VariantProps {} +export interface BadgeProps extends React.HTMLAttributes, VariantProps {} function Badge({ className, variant, ...props }: BadgeProps) { - return ( -
- ) + return
; } -export { Badge, badgeVariants } +export { Badge, badgeVariants }; diff --git a/data/clients/Http.ts b/data/clients/Http.ts index 1774e7f..1649d69 100644 --- a/data/clients/Http.ts +++ b/data/clients/Http.ts @@ -1,3 +1,7 @@ +import { isServer } from '@tanstack/react-query'; + +import { SITE_URL } from '@/env'; + type Search = Record; class Http { diff --git a/data/clients/movieAdvisor.ts b/data/clients/movieAdvisor.ts index 0524317..df433fb 100644 --- a/data/clients/movieAdvisor.ts +++ b/data/clients/movieAdvisor.ts @@ -1,10 +1,14 @@ +import { isServer } from '@tanstack/react-query'; + import Http from './Http'; const BASE = - process.env.NEXT_PUBLIC_VERCEL_ENV === 'production' - ? process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL - : process.env.NEXT_PUBLIC_VERCEL_URL; + process.env.NEXT_VERCEL_ENV === 'production' + ? process.env.NEXT_VERCEL_PROJECT_PRODUCTION_URL + : process.env.NEXT_VERCEL_URL; -const movieAdvisor = new Http(`${BASE?.startsWith('http') ? BASE : `https://${BASE}`}/api/tmdb`); +const ROOT = isServer ? `${BASE?.startsWith('http') ? BASE : `https://${BASE}`}` : ''; + +const movieAdvisor = new Http(`${ROOT}/api/tmdb`); export default movieAdvisor; diff --git a/data/clients/theMovieDb.ts b/data/clients/theMovieDb.ts index 5c180be..f9d5614 100644 --- a/data/clients/theMovieDb.ts +++ b/data/clients/theMovieDb.ts @@ -1,7 +1,7 @@ -import { MOVIE_DB_TOKEN } from '@/env'; +import { MOVIE_DB_API_URL, MOVIE_DB_TOKEN } from '@/env'; import Http from './Http'; -const theMovieDb = new Http('https://api.themoviedb.org/3', `Bearer ${MOVIE_DB_TOKEN}`); +const theMovieDB = new Http(MOVIE_DB_API_URL, `Bearer ${MOVIE_DB_TOKEN}`); -export default theMovieDb; +export default theMovieDB; diff --git a/data/index.ts b/data/index.ts index a0d554e..019e056 100644 --- a/data/index.ts +++ b/data/index.ts @@ -2,74 +2,22 @@ import { cookies } from 'next/headers'; -import http from './clients/theMovieDb'; -import mapMoviesSeriesResponseToShows from './dto/Show'; +import theMovieDB from './clients/theMovieDB'; export const session = async () => cookies().get('session')?.value; export const createRequestToken = async () => { - return http.get('/authentication/token/new', { preventCache: true }).then(({ request_token }) => ({ - redirectUrl: `https://www.themoviedb.org/authenticate/${request_token}`, - requestToken: request_token - })); + return theMovieDB + .get('/authentication/token/new', { preventCache: true }) + .then(({ request_token }) => ({ + redirectUrl: `https://www.themoviedb.org/authenticate/${request_token}`, + requestToken: request_token + })); }; export const createSession = async ({ requestToken }: { requestToken: string }) => { - return http.post('/authentication/session/new', { + return theMovieDB.post('/authentication/session/new', { params: { request_token: requestToken }, preventCache: true }); }; - -export const account = async () => { - return http.get('/account/null', { - params: { session_id: await session() }, - preventCache: true - }); -}; - -export const accountStates = async ({ showId, showType }: { showId: Show['id']; showType: Show['type'] }) => { - return http.get(`/${showType}/${showId}/account_states`, { - params: { session_id: await session() }, - preventCache: true - }); -}; - -export const updateAccountStates = async ({ - showId, - showType, - list, - value -}: { - showId: Show['id']; - showType: Show['type']; - list: 'favorite' | 'watchlist'; - value: boolean; -}) => { - http.post( - `/account/null/${list}`, - { params: { session_id: await session() }, preventCache: true }, - { - media_id: showId, - media_type: showType, - [list]: value - } - ); -}; - -export const usersShows = async ({ - showType, - list, - page -}: { - showType: Show['type']; - list: 'favorite' | 'watchlist'; - page: string; -}): Promise> => { - return http - .get>(`/account/null/${list}/${showType === 'tv' ? 'tv' : 'movies'}`, { - params: { page, sort_by: 'created_at.desc', session_id: await session() }, - preventCache: true - }) - .then((response) => mapMoviesSeriesResponseToShows(response, showType)); -}; diff --git a/data/mutations/accountStates.ts b/data/mutations/accountStates.ts new file mode 100644 index 0000000..92994c9 --- /dev/null +++ b/data/mutations/accountStates.ts @@ -0,0 +1,28 @@ +import movieAdvisor from '../clients/movieAdvisor'; + +export type StatesMutationProps = { + session?: string; +}; + +export type StatesMutationFnProps = { + showId: Show['id']; + showType: Show['type']; + list: 'favorite' | 'watchlist'; + value: boolean; +}; + +const statesMutation = ({ session }: StatesMutationProps) => ({ + retry: 2, + mutationFn: ({ showId, showType, list, value }: StatesMutationFnProps) => + movieAdvisor.post( + `/account/null/${list}`, + { params: { session_id: session }, preventCache: true }, + { + media_id: showId, + media_type: showType, + [list]: value + } + ) +}); + +export default statesMutation; diff --git a/data/queries/accountStates.ts b/data/queries/accountStates.ts new file mode 100644 index 0000000..7196b91 --- /dev/null +++ b/data/queries/accountStates.ts @@ -0,0 +1,16 @@ +import movieAdvisor from '../clients/movieAdvisor'; + +export type StatesQueryProps = { showId?: Show['id']; showType?: Show['type']; session?: string }; + +const statesQuery = ({ showId, showType, session }: StatesQueryProps) => ({ + enabled: Boolean(showId), + queryKey: ['states', showId, showType, session], + staleTime: Infinity, + queryFn: () => + movieAdvisor.get(`/${showType}/${showId}/account_states`, { + params: { session_id: session }, + preventCache: true + }) +}); + +export default statesQuery; diff --git a/env.ts b/env.ts index f31f059..3923f28 100644 --- a/env.ts +++ b/env.ts @@ -5,7 +5,10 @@ const BASE = ? process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL : process.env.NEXT_PUBLIC_VERCEL_URL; export const SITE_URL = `${BASE?.startsWith('http') ? BASE : `https://${BASE}`}`; + export const MOVIE_DB_TOKEN = process.env.MOVIE_DB_TOKEN; +export const MOVIE_DB_API_URL = process.env.MOVIE_DB_API_URL || 'https://api.themoviedb.org/3'; + export const STREAM_URL = `${process.env.NEXT_PUBLIC_TORRENT_PROXY}/stream`; export const TOLOKA_HOST = process.env.TOLOKA_HOST; diff --git a/hooks/useShowState.ts b/hooks/useShowState.ts index 8e88f89..424cabf 100644 --- a/hooks/useShowState.ts +++ b/hooks/useShowState.ts @@ -1,27 +1,19 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; +import statesMutation from '@/data/mutations/accountStates'; +import statesQuery from '@/data/queries/accountStates'; import { KEY as USERS_SHOWS_KEY } from '@/data/queries/usersShows'; -import { accountStates, updateAccountStates } from '../data'; - import { useFavorites, useFavoritesStateToggle, useWatchList, useWatchListStateToggle } from './useLocalUsersLists'; import { useSession } from './useSession'; -const KEY = ['show-state']; - const useShowState = ({ showId, showType = 'movie' }: { showId?: Show['id']; showType?: Show['type'] }) => { const session = useSession(); const { map: favorites } = useFavorites(); const { map: watchList } = useWatchList(); - const query = useQuery({ - enabled: Boolean(session && showId && showType), - queryKey: KEY.concat(showId!.toString(), showType), - queryFn: () => accountStates({ showId: showId!, showType }), - notifyOnChangeProps: ['data'], - staleTime: Infinity - }); + const query = useQuery(statesQuery({ showId, showType, session })); return session ? query.data : { id: showId, watchlist: watchList.has(showId!), favorite: favorites.has(showId!) }; }; @@ -35,9 +27,9 @@ export const useMutateShowState = (show: Show) => { const queryClient = useQueryClient(); const mutation = useMutation({ - mutationFn: updateAccountStates, + ...statesMutation({ session }), onMutate({ showId, showType, list, value }) { - const key = KEY.concat(showId.toString(), showType); + const key = statesQuery({ showId, showType, session }).queryKey; const snapshot = queryClient.getQueryData(key); @@ -46,7 +38,7 @@ export const useMutateShowState = (show: Show) => { return snapshot; }, onError(_, { showId, showType }, snapshot) { - const key = KEY.concat(showId.toString(), showType); + const key = statesQuery({ showId, showType, session }).queryKey; queryClient.setQueryData(key, snapshot); }, diff --git a/hooks/useUsersShows.ts b/hooks/useUsersShows.ts index 2975cc3..7072c0b 100644 --- a/hooks/useUsersShows.ts +++ b/hooks/useUsersShows.ts @@ -24,10 +24,7 @@ const useUsersShows = ({ const { shows: favorite } = useFavorites(); const { shows: watchlist } = useWatchList(); - const query = useInfiniteList({ - ...usersShowsQuery({ showType, list, session }), - enabled: Boolean(session) - }); + const query = useInfiniteList(usersShowsQuery({ showType, list, session })); return session ? query diff --git a/public/sw.js b/public/sw.js index 4138408..e06bfdb 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1 +1 @@ -if(!self.define){let e,s={};const a=(a,i)=>(a=new URL(a+".js",i).href,s[a]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=a,e.onload=s,document.head.appendChild(e)}else e=a,importScripts(a),s()})).then((()=>{let e=s[a];if(!e)throw new Error(`Module ${a} didn’t register its module`);return e})));self.define=(i,n)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let c={};const r=e=>a(e,t),o={module:{uri:t},exports:c,require:r};s[t]=Promise.all(i.map((e=>o[e]||r(e)))).then((e=>(n(...e),c)))}}define(["./workbox-4754cb34"],(function(e){"use strict";importScripts(),self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"/_next/app-build-manifest.json",revision:"f415a7ade9051b0c1537acf9ed55a083"},{url:"/_next/static/chunks/152.f47729bb9b123937.js",revision:"f47729bb9b123937"},{url:"/_next/static/chunks/18-10b5aadb2f65dcdd.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/209-122137a04eb2adce.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/23-e95fe3862375276d.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/26.286553a5ff2812fc.js",revision:"286553a5ff2812fc"},{url:"/_next/static/chunks/276.c3c1130f2adade69.js",revision:"c3c1130f2adade69"},{url:"/_next/static/chunks/305-b973937e3a05106a.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/344.05938a041227e582.js",revision:"05938a041227e582"},{url:"/_next/static/chunks/383.78d47f7582340f53.js",revision:"78d47f7582340f53"},{url:"/_next/static/chunks/43-1b27b4a4ece03023.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/460.ac20021c7496f1d6.js",revision:"ac20021c7496f1d6"},{url:"/_next/static/chunks/497.48f1dfd129122432.js",revision:"48f1dfd129122432"},{url:"/_next/static/chunks/61.e269d4a699fba0b6.js",revision:"e269d4a699fba0b6"},{url:"/_next/static/chunks/621-fa4d2ff1cf645813.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/673.362c29137dd3e968.js",revision:"362c29137dd3e968"},{url:"/_next/static/chunks/695.156d21364de6e419.js",revision:"156d21364de6e419"},{url:"/_next/static/chunks/755.5cd959eac5682527.js",revision:"5cd959eac5682527"},{url:"/_next/static/chunks/792.b51012549074b93f.js",revision:"b51012549074b93f"},{url:"/_next/static/chunks/810.6105e84414768b0d.js",revision:"6105e84414768b0d"},{url:"/_next/static/chunks/922.9ce4bf0553cfb724.js",revision:"9ce4bf0553cfb724"},{url:"/_next/static/chunks/app/(site)/favorites/page-0dcef32535bf7681.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/app/(site)/loading-96645736797edde7.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/app/(site)/page-391352edf67d4bf1.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/app/(site)/popular/page-047d9b7c4949d909.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/app/(site)/similar/page-0b2f61ca98aff38e.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/app/(site)/starring/page-a30349fc64784ca7.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/app/(site)/top/page-8ed26b82343f54cf.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/app/(site)/watch-list/page-526c511ac32b4e16.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/app/_not-found/page-aa0c8e90320336c2.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/app/layout-aa70c1250bb51638.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/c8bcbd21.63daf74955ffea8b.js",revision:"63daf74955ffea8b"},{url:"/_next/static/chunks/fd9d1056-bdf7d185613ab264.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/framework-f66176bb897dc684.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/main-a339d49e77d6dbd3.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/main-app-51cdaff1a81e6b49.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/pages/_app-6a626577ffa902a4.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/pages/_error-1be831200e60c5c0.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/chunks/polyfills-42372ed130431b0a.js",revision:"846118c33b2c0e922d7b3a7676f81f6f"},{url:"/_next/static/chunks/webpack-0c8c94a0b2c005e4.js",revision:"y3saS9mrX4-jigNe-MjDa"},{url:"/_next/static/css/0d5f6452b2682b9b.css",revision:"0d5f6452b2682b9b"},{url:"/_next/static/css/30fc28b4ca88767d.css",revision:"30fc28b4ca88767d"},{url:"/_next/static/media/a9b1453781eac9e6-s.p.woff2",revision:"c754cf60aba699077f00948285bf54b5"},{url:"/_next/static/media/dd843ebd3ff03195-s.p.woff2",revision:"333341dc4117f45b7fcee6b5223a56db"},{url:"/_next/static/media/e9ecf55e71a874cd-s.woff2",revision:"62348655e2d5baed97a39f0590491d09"},{url:"/_next/static/y3saS9mrX4-jigNe-MjDa/_buildManifest.js",revision:"2ec694eb52ae4f523f265a46bae4d768"},{url:"/_next/static/y3saS9mrX4-jigNe-MjDa/_ssgManifest.js",revision:"b6652df95db52feb4daf4eca35380933"},{url:"/apple-touch-icon.png",revision:"6ed7ad78b222698b2872b5a7f104fe08"},{url:"/favicon-48x48.png",revision:"d2db6eb5ce8ce1da63114250c9652da7"},{url:"/favicon.ico",revision:"d7c46eb2b2574863f72315ed861b1c99"},{url:"/favicon.svg",revision:"15b76ab693bd3a8320d8f8778332d396"},{url:"/manifest.json",revision:"5707bda32aaccb2ce142908f0baf8a1b"},{url:"/web-app-manifest-192x192.png",revision:"5d8538e4362b4ddbd7ff195fb24c25dc"},{url:"/web-app-manifest-512x512.png",revision:"e0a092cab607727cbe6f61adb0b1e6cf"}],{ignoreURLParametersMatching:[]}),e.cleanupOutdatedCaches(),e.registerRoute("/",new e.NetworkFirst({cacheName:"start-url",plugins:[{cacheWillUpdate:async({request:e,response:s,event:a,state:i})=>s&&"opaqueredirect"===s.type?new Response(s.body,{status:200,statusText:"OK",headers:s.headers}):s}]}),"GET"),e.registerRoute(/^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,new e.CacheFirst({cacheName:"google-fonts-webfonts",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:31536e3})]}),"GET"),e.registerRoute(/^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,new e.StaleWhileRevalidate({cacheName:"google-fonts-stylesheets",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800})]}),"GET"),e.registerRoute(/\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,new e.StaleWhileRevalidate({cacheName:"static-font-assets",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800})]}),"GET"),e.registerRoute(/\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,new e.StaleWhileRevalidate({cacheName:"static-image-assets",plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\/_next\/image\?url=.+$/i,new e.StaleWhileRevalidate({cacheName:"next-image",plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:mp3|wav|ogg)$/i,new e.CacheFirst({cacheName:"static-audio-assets",plugins:[new e.RangeRequestsPlugin,new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:mp4)$/i,new e.CacheFirst({cacheName:"static-video-assets",plugins:[new e.RangeRequestsPlugin,new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:js)$/i,new e.StaleWhileRevalidate({cacheName:"static-js-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:css|less)$/i,new e.StaleWhileRevalidate({cacheName:"static-style-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\/_next\/data\/.+\/.+\.json$/i,new e.StaleWhileRevalidate({cacheName:"next-data",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:json|xml|csv)$/i,new e.NetworkFirst({cacheName:"static-data-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>{if(!(self.origin===e.origin))return!1;const s=e.pathname;return!s.startsWith("/api/auth/")&&!!s.startsWith("/api/")}),new e.NetworkFirst({cacheName:"apis",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:16,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>{if(!(self.origin===e.origin))return!1;return!e.pathname.startsWith("/api/")}),new e.NetworkFirst({cacheName:"others",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>!(self.origin===e.origin)),new e.NetworkFirst({cacheName:"cross-origin",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:3600})]}),"GET")})); +if(!self.define){let e,s={};const n=(n,a)=>(n=new URL(n+".js",a).href,s[n]||new Promise((s=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=s,document.head.appendChild(e)}else e=n,importScripts(n),s()})).then((()=>{let e=s[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e})));self.define=(a,t)=>{const i=e||("document"in self?document.currentScript.src:"")||location.href;if(s[i])return;let c={};const r=e=>n(e,i),o={module:{uri:i},exports:c,require:r};s[i]=Promise.all(a.map((e=>o[e]||r(e)))).then((e=>(t(...e),c)))}}define(["./workbox-4754cb34"],(function(e){"use strict";importScripts(),self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"/_next/app-build-manifest.json",revision:"59a16d04bfb517ba448006e887fc052b"},{url:"/_next/static/chunks/152.b96372f7a5392cef.js",revision:"b96372f7a5392cef"},{url:"/_next/static/chunks/18-28d875ee028d040c.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/209-a28b87ccff6a966d.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/23-e95fe3862375276d.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/26.286553a5ff2812fc.js",revision:"286553a5ff2812fc"},{url:"/_next/static/chunks/276.c3c1130f2adade69.js",revision:"c3c1130f2adade69"},{url:"/_next/static/chunks/344.05938a041227e582.js",revision:"05938a041227e582"},{url:"/_next/static/chunks/383.78d47f7582340f53.js",revision:"78d47f7582340f53"},{url:"/_next/static/chunks/460.ac20021c7496f1d6.js",revision:"ac20021c7496f1d6"},{url:"/_next/static/chunks/497.48f1dfd129122432.js",revision:"48f1dfd129122432"},{url:"/_next/static/chunks/61.e269d4a699fba0b6.js",revision:"e269d4a699fba0b6"},{url:"/_next/static/chunks/621-fa4d2ff1cf645813.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/671-a5dd76385a5ca3dc.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/673.362c29137dd3e968.js",revision:"362c29137dd3e968"},{url:"/_next/static/chunks/695.156d21364de6e419.js",revision:"156d21364de6e419"},{url:"/_next/static/chunks/734-18050d0326d4613b.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/755.5cd959eac5682527.js",revision:"5cd959eac5682527"},{url:"/_next/static/chunks/792.b51012549074b93f.js",revision:"b51012549074b93f"},{url:"/_next/static/chunks/810.6105e84414768b0d.js",revision:"6105e84414768b0d"},{url:"/_next/static/chunks/922.9ce4bf0553cfb724.js",revision:"9ce4bf0553cfb724"},{url:"/_next/static/chunks/app/(site)/favorites/page-af6260f0ceafa9de.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/app/(site)/loading-96645736797edde7.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/app/(site)/page-3a033d739c48d7a8.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/app/(site)/popular/page-0ed5b2a9fc6cea8d.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/app/(site)/similar/page-b9ebe2e6e227ec5b.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/app/(site)/starring/page-fc1156f9976df849.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/app/(site)/top/page-2c9b5df6a2dfaeef.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/app/(site)/watch-list/page-7f447e5a42b09a54.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/app/_not-found/page-aa0c8e90320336c2.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/app/layout-c04cc3ba56f24f68.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/c8bcbd21.63daf74955ffea8b.js",revision:"63daf74955ffea8b"},{url:"/_next/static/chunks/fd9d1056-bdf7d185613ab264.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/framework-f66176bb897dc684.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/main-a339d49e77d6dbd3.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/main-app-51cdaff1a81e6b49.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/pages/_app-6a626577ffa902a4.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/pages/_error-1be831200e60c5c0.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/chunks/polyfills-42372ed130431b0a.js",revision:"846118c33b2c0e922d7b3a7676f81f6f"},{url:"/_next/static/chunks/webpack-c50673da9d5d6a15.js",revision:"yk9rNjWmbZr4TZ8mBjIkJ"},{url:"/_next/static/css/0d5f6452b2682b9b.css",revision:"0d5f6452b2682b9b"},{url:"/_next/static/css/30fc28b4ca88767d.css",revision:"30fc28b4ca88767d"},{url:"/_next/static/media/a9b1453781eac9e6-s.p.woff2",revision:"c754cf60aba699077f00948285bf54b5"},{url:"/_next/static/media/dd843ebd3ff03195-s.p.woff2",revision:"333341dc4117f45b7fcee6b5223a56db"},{url:"/_next/static/media/e9ecf55e71a874cd-s.woff2",revision:"62348655e2d5baed97a39f0590491d09"},{url:"/_next/static/yk9rNjWmbZr4TZ8mBjIkJ/_buildManifest.js",revision:"2ec694eb52ae4f523f265a46bae4d768"},{url:"/_next/static/yk9rNjWmbZr4TZ8mBjIkJ/_ssgManifest.js",revision:"b6652df95db52feb4daf4eca35380933"},{url:"/apple-touch-icon.png",revision:"6ed7ad78b222698b2872b5a7f104fe08"},{url:"/favicon-48x48.png",revision:"d2db6eb5ce8ce1da63114250c9652da7"},{url:"/favicon.ico",revision:"d7c46eb2b2574863f72315ed861b1c99"},{url:"/favicon.svg",revision:"15b76ab693bd3a8320d8f8778332d396"},{url:"/manifest.json",revision:"5707bda32aaccb2ce142908f0baf8a1b"},{url:"/web-app-manifest-192x192.png",revision:"5d8538e4362b4ddbd7ff195fb24c25dc"},{url:"/web-app-manifest-512x512.png",revision:"e0a092cab607727cbe6f61adb0b1e6cf"}],{ignoreURLParametersMatching:[]}),e.cleanupOutdatedCaches(),e.registerRoute("/",new e.NetworkFirst({cacheName:"start-url",plugins:[{cacheWillUpdate:async({request:e,response:s,event:n,state:a})=>s&&"opaqueredirect"===s.type?new Response(s.body,{status:200,statusText:"OK",headers:s.headers}):s}]}),"GET"),e.registerRoute(/^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,new e.CacheFirst({cacheName:"google-fonts-webfonts",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:31536e3})]}),"GET"),e.registerRoute(/^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,new e.StaleWhileRevalidate({cacheName:"google-fonts-stylesheets",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800})]}),"GET"),e.registerRoute(/\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,new e.StaleWhileRevalidate({cacheName:"static-font-assets",plugins:[new e.ExpirationPlugin({maxEntries:4,maxAgeSeconds:604800})]}),"GET"),e.registerRoute(/\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,new e.StaleWhileRevalidate({cacheName:"static-image-assets",plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\/_next\/image\?url=.+$/i,new e.StaleWhileRevalidate({cacheName:"next-image",plugins:[new e.ExpirationPlugin({maxEntries:64,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:mp3|wav|ogg)$/i,new e.CacheFirst({cacheName:"static-audio-assets",plugins:[new e.RangeRequestsPlugin,new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:mp4)$/i,new e.CacheFirst({cacheName:"static-video-assets",plugins:[new e.RangeRequestsPlugin,new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:js)$/i,new e.StaleWhileRevalidate({cacheName:"static-js-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:css|less)$/i,new e.StaleWhileRevalidate({cacheName:"static-style-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\/_next\/data\/.+\/.+\.json$/i,new e.StaleWhileRevalidate({cacheName:"next-data",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute(/\.(?:json|xml|csv)$/i,new e.NetworkFirst({cacheName:"static-data-assets",plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>{if(!(self.origin===e.origin))return!1;const s=e.pathname;return!s.startsWith("/api/auth/")&&!!s.startsWith("/api/")}),new e.NetworkFirst({cacheName:"apis",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:16,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>{if(!(self.origin===e.origin))return!1;return!e.pathname.startsWith("/api/")}),new e.NetworkFirst({cacheName:"others",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:86400})]}),"GET"),e.registerRoute((({url:e})=>!(self.origin===e.origin)),new e.NetworkFirst({cacheName:"cross-origin",networkTimeoutSeconds:10,plugins:[new e.ExpirationPlugin({maxEntries:32,maxAgeSeconds:3600})]}),"GET")}));