complete server-side streaming

This commit is contained in:
La macchina desiderante 2024-05-21 22:08:55 +02:00
parent d8af939e31
commit 1ad9b46ea3
2 changed files with 14 additions and 2 deletions

View File

@ -1,8 +1,9 @@
import { Platforms } from "@/meta/settings";
import axios from "axios"; import axios from "axios";
type GetParams = { type GetParams = {
params: { params: {
platform: string platform: Platforms
encodedUrl: string encodedUrl: string
}; };
}; };
@ -11,6 +12,16 @@ export async function GET(req: Request, { params }: GetParams) {
const { platform, encodedUrl } = params; const { platform, encodedUrl } = params;
if (!Object.keys(Platforms).includes(platform)) {
return Response.json(
{
success: false,
message: 'Platform not supported!'
},
{ status: 404 }
)
}
const decodedUrl = decodeURIComponent(encodedUrl) const decodedUrl = decodeURIComponent(encodedUrl)
const response = await axios.get<ReadableStream>(decodedUrl, { const response = await axios.get<ReadableStream>(decodedUrl, {

View File

@ -2,6 +2,7 @@ import { PORNHUB_BASE_URL } from "@/constants/urls"
import axios, { AxiosHeaders } from "axios" import axios, { AxiosHeaders } from "axios"
import { getHeadersWithCookie } from "../common/headers" import { getHeadersWithCookie } from "../common/headers"
import { VideoSourceItem } from "@/meta/data" import { VideoSourceItem } from "@/meta/data"
import { Platforms } from "@/meta/settings"
interface PornHubVideoSrcElem { interface PornHubVideoSrcElem {
videoUrl: string videoUrl: string
@ -28,7 +29,7 @@ export const getPornHubMediaUrlList = async (url: string, sessionCookie: string)
if (response.data) { if (response.data) {
videos = await response.data.map((elem: PornHubVideoSrcElem) => ({ videos = await response.data.map((elem: PornHubVideoSrcElem) => ({
src: elem?.videoUrl, src: `/api/stream/${Platforms.pornhub}/${encodeURIComponent(elem?.videoUrl)}`,
type: 'video/mp4', type: 'video/mp4',
size: elem?.quality size: elem?.quality
})) as VideoSourceItem[] })) as VideoSourceItem[]