diff --git a/src/app/api/stream/[filename]/route.ts b/src/app/api/stream/[filename]/route.ts new file mode 100644 index 0000000..4dcbb26 --- /dev/null +++ b/src/app/api/stream/[filename]/route.ts @@ -0,0 +1,35 @@ +import axios from "axios"; + +type GetParams = { + params: { + filename: string; + }; +}; + +// export an async GET function. This is a convention in NextJS +export async function GET(req: Request, { params }: GetParams) { + // filename for the file that the user is trying to download + const filename = params.filename; + + // external file URL + const DUMMY_URL = + "https://ev.phncdn.com/videos/202404/23/451452671/1080P_4000K_451452671.mp4?validfrom=1715716033&validto=1715723233&rate=50000k&burst=50000k&ip=104.28.241.69&ipa=104.28.241.69&hash=DY4%2Fxb3xItQX4zcl3F%2F3gW8WlYU%3D"; + + // use fetch to get a response + const response = await axios.get(DUMMY_URL, { + responseType: "stream", + }); + + // apre lo stream nel browser + return new Response(response.data); + + // return a new response but use 'content-disposition' to suggest saving the file to the user's computer + + + // return new Response(response.data, { + // headers: { + // "content-disposition": `attachment; filename="${filename}"`, + // }, + // }); +} +