Update server.js
Browse files
server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
// File: app.js
|
| 2 |
|
| 3 |
import express from "express";
|
| 4 |
-
import bodyParser
|
| 5 |
import ytdl from "@distube/ytdl-core";
|
| 6 |
import yts from "youtube-yts";
|
| 7 |
|
|
@@ -11,12 +11,12 @@ const PORT = 3000;
|
|
| 11 |
// Middleware
|
| 12 |
app.use(bodyParser.json());
|
| 13 |
|
| 14 |
-
//
|
| 15 |
app.get("/download", async (req, res) => {
|
| 16 |
-
const { url, query } = req.
|
| 17 |
|
| 18 |
if (!url && !query) {
|
| 19 |
-
return res.status(400).json({ error: "Either 'url' or 'query' must be provided." });
|
| 20 |
}
|
| 21 |
|
| 22 |
try {
|
|
|
|
| 1 |
// File: app.js
|
| 2 |
|
| 3 |
import express from "express";
|
| 4 |
+
import bodyParser from "body-parser";
|
| 5 |
import ytdl from "@distube/ytdl-core";
|
| 6 |
import yts from "youtube-yts";
|
| 7 |
|
|
|
|
| 11 |
// Middleware
|
| 12 |
app.use(bodyParser.json());
|
| 13 |
|
| 14 |
+
// GET endpoint for downloading YouTube videos
|
| 15 |
app.get("/download", async (req, res) => {
|
| 16 |
+
const { url, query } = req.query; // Extract parameters from query
|
| 17 |
|
| 18 |
if (!url && !query) {
|
| 19 |
+
return res.status(400).json({ error: "Either 'url' or 'query' must be provided as a query parameter." });
|
| 20 |
}
|
| 21 |
|
| 22 |
try {
|