diff --git a/package.json b/package.json index 98188c4..7c3b625 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,7 @@ "react-dom": "18.2.0", "react-icons": "^4.8.0", "tailwindcss": "^3.3.2", - "typescript": "5.0.4", - "ytdl-core": "npm:@distube/ytdl-core@^4.11.9" + "typescript": "5.0.4" }, "devDependencies": { "@types/downloadjs": "^1.4.3" diff --git a/src/pages/api/download.ts b/src/pages/api/download.ts deleted file mode 100644 index f9e7ca3..0000000 --- a/src/pages/api/download.ts +++ /dev/null @@ -1,36 +0,0 @@ -import type { NextApiRequest, NextApiResponse } from "next"; -const ytdl = require("ytdl-core"); - -export default async function handler( - req: NextApiRequest, - res: NextApiResponse -) { - if (req.method === "POST") { - try { - const url = req.body.url; - const type = req.body.type; - if (!ytdl.validateURL(url)) - return res.status(400).json({ message: "Invalid URL", code: 400 }); - if (type !== "mp3" && type !== "mp4") - return res.status(400).json({ message: "Invalid type", code: 400 }); - res.setHeader( - "Content-Type", - type === "mp3" ? "audio/mpeg" : "video/mp4" - ); - await ytdl(url, { - format: type, - filter: type == "mp4" ? "videoandaudio" : "audioonly", - }).pipe(res); - } catch (e) { - console.log(e); - } - } else { - res.status(405).json({ message: "Method not allowed", code: 405 }); - } -} - -export const config = { - api: { - responseLimit: false, - }, -}; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index b9cdab1..9230c31 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -28,13 +28,13 @@ export default function Home() { if (videoID) { const title = await getTitle(videoID); try { - fetch("/api/download", { + fetch("https://service-api.night0721.repl.co/api/download", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ url, type }), }) .then(res => res.blob()) - .then(blob => { + .then(async blob => { const sizeInBytes = blob.size; if (sizeInBytes <= 0) { setInfo( @@ -50,6 +50,7 @@ export default function Home() { } }); } catch (err) { + console.error(err); setInfo( "Unable to download! Maybe File size is too high. Try to download video less than 5MB" );