Skip to content

Commit

Permalink
error not found if enter to ep in season splited (#120)
Browse files Browse the repository at this point in the history
* add prop `chapsSibs` for `seasons

* fix: leak memory

* [replace router ep name]: use `currentMetaChap` replaced check `route.params`

* before emit to `not_found` check the seasons guys to see if this ep exists

* fix path route `watch-anime`
  • Loading branch information
tachibana-shin authored May 7, 2023
1 parent 5d8b690 commit 3659413
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 43 deletions.
108 changes: 67 additions & 41 deletions src/pages/phim/_season.vue
Original file line number Diff line number Diff line change
Expand Up @@ -708,36 +708,38 @@ async function fetchSeason(season: string) {
const nameSeason = seasons.value[indexMetaSeason].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, chapsSplited[0].id)
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)
}
seasonsSplited.push({
name,
value,
})
})
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
})`
console.log("set %s by %s", value, chaps[0].id)
const dataOnCache = _cacheDataSeasons.get(value)
const newData: ResponseDataSeasonSuccess = {
status: "success",
response: {
...response,
chaps,
},
}
if (dataOnCache) {
Object.assign(dataOnCache, newData)
} else {
_cacheDataSeasons.set(value, newData)
}
return {
name,
value,
}
}),
...seasonsSplited,
...seasons.value.slice(indexMetaSeason + 1),
]
console.log("current seasons: ", seasons.value)
Expand Down Expand Up @@ -895,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
Expand Down
6 changes: 5 additions & 1 deletion src/pages/phim/response-data-season.ts
Original file line number Diff line number Diff line change
@@ -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<ReturnType<typeof PhimIdChap>>
response: Awaited<ReturnType<typeof PhimIdChap>> & {
ssSibs?: Season[]
}
}
export interface ResponseDataSeasonError {
status: "error"
Expand Down
2 changes: 1 addition & 1 deletion src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 3659413

Please sign in to comment.