commit f847cb8d8d8ea8c8136cd661fd2ebd1f952a0222
parent df13398d333db63fbe8a73b7256f652b931880c2
Author: NK <[email protected]>
Date: Thu, 27 Apr 2023 18:12:16 +0100
new domain
Diffstat:
3 files changed, 4 insertions(+), 40 deletions(-)
diff --git 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
@@ -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
@@ -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"
);