44 lines
967 B
TypeScript
44 lines
967 B
TypeScript
import { Platforms } from "@/meta/settings";
|
|
import axios from "axios";
|
|
|
|
type GetParams = {
|
|
params: {
|
|
platform: Platforms
|
|
encodedUrl: string
|
|
};
|
|
};
|
|
|
|
export async function GET(req: Request, { params }: GetParams) {
|
|
|
|
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 response = await axios.get<ReadableStream>(decodedUrl, {
|
|
responseType: "stream",
|
|
});
|
|
|
|
const headers = new Headers();
|
|
|
|
headers.set('Content-Type', 'video/mp4');
|
|
headers.set('Cache-Control', 'no-cache');
|
|
headers.set('Accept-Ranges', 'bytes');
|
|
headers.set('Content-Length', response.headers['content-length']);
|
|
headers.set('Content-Disposition', 'inline');
|
|
|
|
return new Response(response.data, {
|
|
headers,
|
|
});
|
|
}
|
|
|