Skip to content

Commit

Permalink
chore: typo
Browse files Browse the repository at this point in the history
  • Loading branch information
tachibana-shin committed Mar 3, 2024
1 parent 6e111cf commit afd79a6
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 71 deletions.
207 changes: 144 additions & 63 deletions src/apis/parser/[type_normal]/[value].ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,146 @@
import type TypeNormalValueParser from "src/apis/parser/[type_normal]/[value]"
import { useCache } from "src/apis/useCache"
import Worker from "src/apis/workers/[type_normal]/[value]?worker"
import { PostWorker } from "src/apis/wrap-worker"
import { get } from "src/logic/http"

export async function TypeNormalValue(
type: string,
value: string | string[],
page = 1,
onlyItems: boolean,
options?: {
genres: string[]
seaser: string | null
sorter: string | null
typer: string | null
year: string | null
},
defaultsOptions: {
genres?: string
seaser?: string
typer?: string
year?: string
} = {}
import { getInfoTPost } from "../__helpers__/getInfoTPost"
import { parserDom } from "../__helpers__/parserDom"

export default function TypeNormalValue(
html: string,
now: number,
onlyItems: boolean
) {
const isCustom =
options &&
(options.genres.length > 1 ||
options.seaser ||
options.typer ||
options.year ||
/* exclude */ type === "danh-sach")

const url = isCustom
? [
"/danh-sach",
options.typer ?? defaultsOptions.typer ?? "all",
options.genres
.concat(
defaultsOptions.typer && defaultsOptions.typer !== "all"
? [defaultsOptions.typer]
: []
)
.join("-") || "all",
options.seaser ?? defaultsOptions.seaser ?? "all",
options.year ?? defaultsOptions.year ?? "all",
`/trang-${page}.html`
].join("/") + (options.sorter ? "?sort=" + options.sorter : "")
: `/${type}/${
Array.isArray(value) ? value.join("/") : value
}/trang-${page}.html` + (options?.sorter ? "?sort=" + options.sorter : "")

return await useCache(url, async () => {
const { data: html } = await get(url)

const now = Date.now()

return PostWorker<typeof TypeNormalValueParser>(
Worker,
html,
now,
onlyItems
)
})
const $ = parserDom(html)

const items = $(".MovieList:eq(0)")
.find(".TPostMv")
.map((_i, item) => getInfoTPost($(item), now))
.toArray()
const curPage = parseInt(
$(".current").attr("data") ?? $(".current").attr("title") ?? "1"
)
const maxPage = parseInt(
$(".larger:last-child, .wp-pagenavi > *:last-child").attr("data") ??
$(".larger:last-child, .wp-pagenavi > *:last-child").attr("title") ??
"1"
)

if (onlyItems) {
return { items, curPage, maxPage }
}

const title = $(".breadcrumb:eq(0) > li")
.slice(1)
.map((_i, item) => $(item).text().trim())
.toArray()
.join(" ")
.replace(/:/g, "")
.replace(/^Danh sách /i, "")

const filter = {
sorter: $("#filter")
.find(".fc-main-list > li > a")
.map((_i, anchor) => {
const text = $(anchor).text()
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const value = new URL(
$(anchor).attr("href") ?? "",
"https://example.com"
).searchParams.get("sort")!
return { text, value }
})
.toArray(),
typer: $("#filter")
.find(".fc-filmtype label")
.map((_i, item) => {
const $item = $(item)

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const value = $item.find("input").attr("value")!
const checked = !!$item.attr("checked")

// eslint-disable-next-line array-callback-return
if (value === "all") return

const text = $(item).text()

return {
text,
value,
checked
}
})
.toArray()
.filter(Boolean),
seaser: $("#filter")
.find(".fc-quality label")
.map((_i, item) => {
const $item = $(item)

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const value = $item.find("input").attr("value")!
const checked = !!$item.attr("checked")

// eslint-disable-next-line array-callback-return
if (value === "all") return

const text = $(item).text()

return {
text,
value,
checked
}
})
.toArray()
.filter(Boolean),
gener: $("#filter")
.find(".fc-genre label")
.map((_i, item) => {
const $item = $(item)

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const value = $(item).find("input").attr("value")!
const checked = !!$item.attr("checked")

// eslint-disable-next-line array-callback-return
if (value === "all") return

const text = $(item).text()

return {
text,
value,
checked
}
})
.toArray()
.filter(Boolean),
year: $("#filter")
.find(".fc-release label")
.map((_i, item) => {
const $item = $(item)

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const value = $(item).find("input").attr("value")!
const checked = !!$item.attr("checked")

// eslint-disable-next-line array-callback-return
if (value === "all") return

const text = $(item).text()

return {
text,
value,
checked
}
})
.toArray()
.filter(Boolean)
}

return {
title,
items,
curPage,
maxPage,
filter
}
}
17 changes: 9 additions & 8 deletions src/pages/[_type-normal]/[value].vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@
no-caps
flat
class="py-2 bg-[#292929] text-weight-normal w-full ease-bg"
:disable="defaultsOptions.gener === item.value"
:disable="defaultsOptions.gener?.includes(item.value)"
@click="toggleGenres(item.value)"
:class="{
'bg-main':
defaultsOptions.gener === item.value ||
defaultsOptions.gener?.includes(item.value) ||
indexInGenres(item.value) > -1,
}"
>{{ item.text }}</q-btn
Expand Down Expand Up @@ -369,11 +369,11 @@
no-caps
flat
class="py-2 bg-[#292929] text-weight-normal w-full min-h-10 ease-bg"
:disable="defaultsOptions.gener === item.value"
:disable="defaultsOptions.gener?.includes(item.value)"
@click="toggleGenres(item.value)"
:class="{
'bg-main':
defaultsOptions.gener === item.value ||
defaultsOptions.gener?.includes(item.value) ||
indexInGenres(item.value) > -1,
}"
>{{ item.text }}</q-btn
Expand Down Expand Up @@ -514,10 +514,11 @@ const showDialogTyper = ref(false)
const showDialogSorter = ref(false)
const showDialogFilter = ref(false)
// eslint-disable-next-line functional/no-let
let inited = false
const defaultsOptions = computed<{
typer?: string
gener?: string
gener?: string[]
seaser?: string
year?: string
}>(() => {
Expand All @@ -532,10 +533,10 @@ const defaultsOptions = computed<{
return {
typer: value,
}
case "the-loai": {
case "the-loai": {
if (inited)
return {
gener: data.value?.filter.gener
gener: data.value?.filter?.gener
.filter((item) => item.checked)
.map((item) => item.value) ?? [value]
}
Expand Down Expand Up @@ -590,7 +591,7 @@ const textFilter = computed(() => {
data.value.filter &&
[
data.value.filter.gener
.filter((item) => allGenres.includes(item.value))
.filter((item) => allGenres.value.includes(item.value))
.map((item) => item.text)
.join(", "),
data.value.filter.seaser.find((item) => item.value === seaser.value)
Expand Down

0 comments on commit afd79a6

Please sign in to comment.