From a58cc663d69e8631e936ebeef1c77284bebca0a1 Mon Sep 17 00:00:00 2001 From: La macchina desiderante Date: Sun, 12 May 2024 14:28:59 +0200 Subject: [PATCH] add platform in video route --- .../[locale]/video/{ => [platform]}/[id]/page.tsx | 13 ++++++++++--- .../Results/Wrapper/Gallery/Thumbnail/index.tsx | 7 +++++-- .../Layout/Results/Wrapper/Gallery/index.tsx | 1 + src/meta/data.ts | 3 +++ src/utils/scrape/xvideos/gallery.ts | 4 +++- 5 files changed, 22 insertions(+), 6 deletions(-) rename src/app/[locale]/video/{ => [platform]}/[id]/page.tsx (63%) diff --git a/src/app/[locale]/video/[id]/page.tsx b/src/app/[locale]/video/[platform]/[id]/page.tsx similarity index 63% rename from src/app/[locale]/video/[id]/page.tsx rename to src/app/[locale]/video/[platform]/[id]/page.tsx index 26d9593..30076b0 100644 --- a/src/app/[locale]/video/[id]/page.tsx +++ b/src/app/[locale]/video/[platform]/[id]/page.tsx @@ -9,12 +9,19 @@ import { decodeVideoUrlPath } from '@/utils/string'; import { fetchVideoData } from '@/utils/scrape/xvideos/video'; import { useLocale } from 'next-intl'; +import { Platforms } from '@/meta/settings'; -export default async function VideoPage({ params }: { params: { id: string } }) { +export default async function VideoPage({ params }: { params: { platform: Platforms, id: string } }) { + + const { platform, id } = params const locale = useLocale() - const decodedId = decodeVideoUrlPath(params.id) + if (!platform || !Object.keys(Platforms).includes(platform)) { + redirect(`/${locale}/404`) + } + + const decodedId = decodeVideoUrlPath(id) const [data, related] = await fetchVideoData(decodedId) @@ -23,6 +30,6 @@ export default async function VideoPage({ params }: { params: { id: string } }) } return - } \ No newline at end of file diff --git a/src/components/Layout/Results/Wrapper/Gallery/Thumbnail/index.tsx b/src/components/Layout/Results/Wrapper/Gallery/Thumbnail/index.tsx index 0dfa939..acc71c0 100644 --- a/src/components/Layout/Results/Wrapper/Gallery/Thumbnail/index.tsx +++ b/src/components/Layout/Results/Wrapper/Gallery/Thumbnail/index.tsx @@ -9,25 +9,28 @@ import classNames from 'classnames'; import Link from 'next/link' import style from './Thumbnail.module.scss' + import { encodeVideoUrlPath } from '@/utils/string'; +import { Platforms } from '@/meta/settings'; interface Props { locale: string videoUrl: string imgUrl: string + platform: Platforms text: string show: boolean } const Thumbnail: React.FC = (props) => { - const { locale, videoUrl, imgUrl, text, show } = props + const { locale, platform, videoUrl, imgUrl, text, show } = props const encodedUri = encodeVideoUrlPath(videoUrl) return (
- +
} />
{text}
diff --git a/src/components/Layout/Results/Wrapper/Gallery/index.tsx b/src/components/Layout/Results/Wrapper/Gallery/index.tsx index 7953758..63d8b77 100644 --- a/src/components/Layout/Results/Wrapper/Gallery/index.tsx +++ b/src/components/Layout/Results/Wrapper/Gallery/index.tsx @@ -27,6 +27,7 @@ const Gallery: React.FC = (props) => { key={key} imgUrl={elem.imgUrl} videoUrl={elem.videoUrl} + platform={elem.platform} text={elem.text} locale={locale} /> })} diff --git a/src/meta/data.ts b/src/meta/data.ts index f8bc93e..1c74f3c 100644 --- a/src/meta/data.ts +++ b/src/meta/data.ts @@ -1,7 +1,10 @@ +import { Platforms } from "./settings" + export interface GalleryData { videoUrl: string imgUrl: string text: string + platform: Platforms } export interface VideoData { diff --git a/src/utils/scrape/xvideos/gallery.ts b/src/utils/scrape/xvideos/gallery.ts index 6efbe55..f008791 100644 --- a/src/utils/scrape/xvideos/gallery.ts +++ b/src/utils/scrape/xvideos/gallery.ts @@ -4,6 +4,7 @@ import axios, { AxiosError } from 'axios'; import * as cheerio from "cheerio"; import { getHeaders } from '../headers'; import { getXVideosQueryUrl } from './url'; +import { Platforms } from '@/meta/settings'; interface FetchParams { baseUrl?: string @@ -37,7 +38,8 @@ export const fetchGalleryData = async (params?: FetchParams): Promise