new domain
This commit is contained in:
parent
df13398d33
commit
f847cb8d8d
3 changed files with 4 additions and 40 deletions
|
@ -19,8 +19,7 @@
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"react-icons": "^4.8.0",
|
"react-icons": "^4.8.0",
|
||||||
"tailwindcss": "^3.3.2",
|
"tailwindcss": "^3.3.2",
|
||||||
"typescript": "5.0.4",
|
"typescript": "5.0.4"
|
||||||
"ytdl-core": "npm:@distube/ytdl-core@^4.11.9"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/downloadjs": "^1.4.3"
|
"@types/downloadjs": "^1.4.3"
|
||||||
|
|
|
@ -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,
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -28,13 +28,13 @@ export default function Home() {
|
||||||
if (videoID) {
|
if (videoID) {
|
||||||
const title = await getTitle(videoID);
|
const title = await getTitle(videoID);
|
||||||
try {
|
try {
|
||||||
fetch("/api/download", {
|
fetch("https://service-api.night0721.repl.co/api/download", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ url, type }),
|
body: JSON.stringify({ url, type }),
|
||||||
})
|
})
|
||||||
.then(res => res.blob())
|
.then(res => res.blob())
|
||||||
.then(blob => {
|
.then(async blob => {
|
||||||
const sizeInBytes = blob.size;
|
const sizeInBytes = blob.size;
|
||||||
if (sizeInBytes <= 0) {
|
if (sizeInBytes <= 0) {
|
||||||
setInfo(
|
setInfo(
|
||||||
|
@ -50,6 +50,7 @@ export default function Home() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
setInfo(
|
setInfo(
|
||||||
"Unable to download! Maybe File size is too high. Try to download video less than 5MB"
|
"Unable to download! Maybe File size is too high. Try to download video less than 5MB"
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue