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

119 error not found if enter to ep in season splited #120

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
120 changes: 71 additions & 49 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 @@ -866,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
Expand All @@ -882,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,
})
Expand All @@ -895,35 +897,55 @@ 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
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

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