From 10e94bc721c9d417a0522da7903edfd373ccd556 Mon Sep 17 00:00:00 2001 From: Tachibana Shin Date: Sun, 7 May 2023 15:15:58 +0000 Subject: [PATCH 1/5] add prop `chapsSibs` for `seasons --- src/pages/phim/_season.vue | 26 ++++++++++++++------------ src/pages/phim/response-data-season.ts | 6 +++++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/pages/phim/_season.vue b/src/pages/phim/_season.vue index 4150ae81..e486b8af 100644 --- a/src/pages/phim/_season.vue +++ b/src/pages/phim/_season.vue @@ -708,23 +708,22 @@ async function fetchSeason(season: string) { const nameSeason = seasons.value[indexMetaSeason].name - const newSeasons = [ - ...seasons.value.slice(0, indexMetaSeason), - ...unflat(chaps, 50).map((chaps, index) => { - const value = - index === 0 ? realIdSeason : `${realIdSeason}$${index}` - const name = `${nameSeason} (${chaps[0].name} - ${ - chaps[chaps.length - 1].name + const seasonsSplited: Season[] = [] + unflat(chaps, 50).forEach((chapsSplited, index) => { + const value = index === 0 ? realIdSeason : `${realIdSeason}$${index}` + const name = `${nameSeason} (${chapsSplited[0].name} - ${ + chapsSplited[chapsSplited.length - 1].name })` - console.log("set %s by %s", value, chaps[0].id) + console.log("set %s by %s", value, chapsSplited[0].id) const dataOnCache = _cacheDataSeasons.get(value) const newData: ResponseDataSeasonSuccess = { status: "success", response: { ...response, - chaps, + chaps: chapsSplited, + ssSibs: seasonsSplited, }, } if (dataOnCache) { @@ -733,11 +732,14 @@ async function fetchSeason(season: string) { _cacheDataSeasons.set(value, newData) } - return { + seasonsSplited.push({ name, value, - } - }), + }) + }) + const newSeasons = [ + ...seasons.value.slice(0, indexMetaSeason), + ...seasonsSplited, ...seasons.value.slice(indexMetaSeason + 1), ] console.log("current seasons: ", seasons.value) diff --git a/src/pages/phim/response-data-season.ts b/src/pages/phim/response-data-season.ts index c7c0ae56..3e92d740 100644 --- a/src/pages/phim/response-data-season.ts +++ b/src/pages/phim/response-data-season.ts @@ -1,11 +1,15 @@ import type PhimIdChap from "src/apis/parser/phim/[id]/[chap]" +import type { Season } from "./_season.interface" + export interface ResponseDataSeasonPending { status: "pending" } export interface ResponseDataSeasonSuccess { status: "success" - response: Awaited> + response: Awaited> & { + ssSibs?: Season[] + } } export interface ResponseDataSeasonError { status: "error" From 15799f54893928c8c6950f32a8401ac82eccb871 Mon Sep 17 00:00:00 2001 From: Tachibana Shin Date: Sun, 7 May 2023 15:16:33 +0000 Subject: [PATCH 2/5] fix: leak memory --- src/pages/phim/_season.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/phim/_season.vue b/src/pages/phim/_season.vue index e486b8af..f618edb2 100644 --- a/src/pages/phim/_season.vue +++ b/src/pages/phim/_season.vue @@ -868,7 +868,7 @@ const currentMetaChap = computed(() => { }) watch( currentSeason, - (season, _, onCleanup) => { + (_, __, onCleanup) => { // replace router if last episode viewing exists const watcherRestoreLastEp = watchPostEffect(() => { const episodeIdFirst = currentDataSeason.value?.chaps[0].id @@ -884,7 +884,7 @@ watch( if (import.meta.env.DEV) console.log("%c Redirect to suspend path", "color: green") router.replace({ - path: `/phim/${season}/${correctChapName}-${currentChap.value}`, + path: `/phim/${route.params.season}/${correctChapName}-${currentChap.value}`, query: route.query, hash: route.hash, }) From 405d7b7052bcbea89fe347d6701ddda9028f388a Mon Sep 17 00:00:00 2001 From: Tachibana Shin Date: Sun, 7 May 2023 15:18:49 +0000 Subject: [PATCH 3/5] [replace router ep name]: use `currentMetaChap` replaced check `route.params` --- src/pages/phim/_season.vue | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pages/phim/_season.vue b/src/pages/phim/_season.vue index f618edb2..55f845a0 100644 --- a/src/pages/phim/_season.vue +++ b/src/pages/phim/_season.vue @@ -918,14 +918,10 @@ watchEffect(() => { }) // TOOD: check chapName in url is chapName watchEffect(() => { - const chaps = currentDataSeason.value?.chaps - if (!chaps) return - - const { chap: epId } = route.params - - const metaEp = epId ? chaps.find((item) => item.id === epId) : undefined + const metaEp = currentMetaChap.value ?? undefined if (!metaEp) return + const epId = metaEp.id const correctChapName = parseChapName(metaEp.name) const urlChapName = route.params.chapName From dcb304ee2d4cf6e7c17fa35c283f60a939c7f5b0 Mon Sep 17 00:00:00 2001 From: Tachibana Shin Date: Sun, 7 May 2023 15:23:46 +0000 Subject: [PATCH 4/5] before emit to `not_found` check the seasons guys to see if this ep exists --- src/pages/phim/_season.vue | 80 +++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/src/pages/phim/_season.vue b/src/pages/phim/_season.vue index 55f845a0..ccca086f 100644 --- a/src/pages/phim/_season.vue +++ b/src/pages/phim/_season.vue @@ -713,28 +713,28 @@ async function fetchSeason(season: string) { const value = index === 0 ? realIdSeason : `${realIdSeason}$${index}` const name = `${nameSeason} (${chapsSplited[0].name} - ${ chapsSplited[chapsSplited.length - 1].name - })` + })` console.log("set %s by %s", value, chapsSplited[0].id) - const dataOnCache = _cacheDataSeasons.get(value) - const newData: ResponseDataSeasonSuccess = { - status: "success", - response: { - ...response, + const dataOnCache = _cacheDataSeasons.get(value) + const newData: ResponseDataSeasonSuccess = { + status: "success", + response: { + ...response, chaps: chapsSplited, ssSibs: seasonsSplited, - }, - } - if (dataOnCache) { - Object.assign(dataOnCache, newData) - } else { - _cacheDataSeasons.set(value, newData) - } + }, + } + if (dataOnCache) { + Object.assign(dataOnCache, newData) + } else { + _cacheDataSeasons.set(value, newData) + } seasonsSplited.push({ - name, - value, + name, + value, }) }) const newSeasons = [ @@ -897,23 +897,47 @@ watch( ) watchEffect(() => { // currentChap != undefined because is load done from firestore and ready show but in chaps not found (!currentMetaChap.value) - const chaps = currentDataSeason.value?.chaps - if (!chaps) return + if (!currentDataSeason.value) return - const { chap: epId } = route.params + if (!currentMetaChap.value) { + const epId = currentChap.value - if (!epId) return + // search on all season siblings (season splited with `$`) + const seasonAccuracy = currentDataSeason.value.ssSibs?.find((season) => { + const cache = _cacheDataSeasons.get(season.value) - if (!chaps.some((item) => item.id === epId)) { - if (import.meta.env.DEV) console.warn("Redirect to not_found") - router.replace({ - name: "not_found", - params: { - catchAll: route.path.split("/").slice(1), - }, - query: route.query, - hash: route.hash, + if (cache?.status !== "success") return false + + if (cache.response.chaps.some((item) => item.id === epId)) { + return true + } + + return false }) + + if (seasonAccuracy) { + if (import.meta.env.DEV) + console.log("Redirect to season %s", seasonAccuracy.value) + router.replace({ + name: "watch-anime", + params: { + ...route.params, + season: seasonAccuracy.value, + }, + query: route.query, + hash: route.hash, + }) + } else { + if (import.meta.env.DEV) console.warn("Redirect to not_found") + router.replace({ + name: "not_found", + params: { + catchAll: route.path.split("/").slice(1), + }, + query: route.query, + hash: route.hash, + }) + } } }) // TOOD: check chapName in url is chapName From bbb43c4103df88a14ac8ffb7925152ff8e2a42ad Mon Sep 17 00:00:00 2001 From: Tachibana Shin Date: Sun, 7 May 2023 15:24:00 +0000 Subject: [PATCH 5/5] fix path route `watch-anime` --- src/router/routes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/routes.ts b/src/router/routes.ts index bbc2cc80..253cb516 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -155,7 +155,7 @@ const routes: RouteRecordRaw[] = [ { name: "watch-anime", - path: "/phim/:season/:chapName(?:(.*\\)-)?:chap(\\d+)?", // [feature or defect] + path: "/phim/:season/:chapName(.+)-:chap(\\d+)", // [feature or defect] alias: ["/phim/:season/:chapName(\\0)?:chap(\\d+)?", "/phim/:season"], component: () => import("pages/phim/_season.vue"), meta: {