Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

62 error not found if enter to ep in season splited #63

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/pages/phim/_season.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export interface ResponseDataSeasonPending {
}
export interface ResponseDataSeasonSuccess {
status: "success"
response: Awaited<ReturnType<typeof PhimIdChap>>
response: Awaited<ReturnType<typeof PhimIdChap>> & {
ssSibs?: Season[]
}
}
export interface ResponseDataSeasonError {
status: "error"
Expand Down
72 changes: 60 additions & 12 deletions src/pages/phim/_season.vue
Original file line number Diff line number Diff line change
Expand Up @@ -847,23 +847,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) {
Expand All @@ -872,11 +871,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)
Expand Down Expand Up @@ -1016,6 +1018,7 @@ const currentMetaChap = computed(() => {
(item) => item.id === currentChap.value
)
})

watch(
currentSeason,
(_, __, onCleanup) => {
Expand Down Expand Up @@ -1043,6 +1046,51 @@ watch(
},
{ immediate: true }
)
watchEffect(() => {
// currentChap != undefined because is load done from firestore and ready show but in chaps not found (!currentMetaChap.value)
if (!currentDataSeason.value) return

if (!currentMetaChap.value) {
const epId = currentChap.value

// search on all season siblings (season splited with `$`)
const seasonAccuracy = currentDataSeason.value.ssSibs?.find((season) => {
const cache = _cacheDataSeasons.get(season.value)

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,
})
}
}
})

const nextChap = computed<
| {
Expand Down
4 changes: 2 additions & 2 deletions src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ const routes: RouteRecordRaw[] = [

{
name: "watch-anime",
path: "/phim/:season/:chapName(?:(.*\\)-)?:chap(\\d+)?", // [feature or defect]
alias: ["/phim/:season/:chapName(\\0)?:chap(\\d+)?", "/phim/:season"],
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: {
screen: {
Expand Down