processed commited on
Commit
6dd6c3a
·
verified ·
1 Parent(s): 4981ba5

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +25 -5
server.js CHANGED
@@ -1,15 +1,17 @@
1
  const express = require('express');
2
- const { tiktokStalk } = require('./lib/tiktokstalk'); // Pastikan file `iask.js` sesuai dengan yang kamu punya
 
3
 
4
  const app = express();
5
  const port = process.env.PORT || 7860; // Hugging Face Spaces menggunakan port 7860
6
 
7
  // Middleware untuk parsing JSON
8
  app.use(express.json());
9
- app.get('/', (req, res) => res.status(400).json({ message: 'Hello World' }))
10
 
11
- // Endpoint utama untuk menjalankan fungsi iask
12
- app.get('/tools/tiktokstalk', async (req, res) => {
 
 
13
  const query = req.query.query; // Mengambil parameter dari query string
14
 
15
  if (!query) {
@@ -25,7 +27,25 @@ app.get('/tools/tiktokstalk', async (req, res) => {
25
  }
26
  });
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  // Menjalankan server
29
  app.listen(port, () => {
30
  console.log(`API running on http://localhost:${port}`);
31
- });
 
1
  const express = require('express');
2
+ const { tiktokStalk } = require('./lib/tiktokstalk'); // Pastikan file `tiktokstalk.js` sesuai
3
+ const { ytdl } = require('./lib/ytdl'); // Modul untuk ytdl
4
 
5
  const app = express();
6
  const port = process.env.PORT || 7860; // Hugging Face Spaces menggunakan port 7860
7
 
8
  // Middleware untuk parsing JSON
9
  app.use(express.json());
 
10
 
11
+ app.get('/', (req, res) => res.status(400).json({ message: 'Hello World' }));
12
+
13
+ // Endpoint untuk TikTok Stalk
14
+ app.get('/endpoint/tiktokstalk', async (req, res) => {
15
  const query = req.query.query; // Mengambil parameter dari query string
16
 
17
  if (!query) {
 
27
  }
28
  });
29
 
30
+ // Endpoint untuk YouTube Download
31
+ app.get('/endpoint/ytdl', async (req, res) => {
32
+ const url = req.query.url; // Mengambil URL dari query string
33
+ const resolution = req.query.resolution || '360p'; // Default resolusi 360p
34
+
35
+ if (!url) {
36
+ return res.status(400).json({ error: 'URL is required' });
37
+ }
38
+
39
+ try {
40
+ const result = await ytdl(url, resolution);
41
+ res.json(result);
42
+ } catch (error) {
43
+ console.error('Error:', error);
44
+ res.status(500).json({ error: 'Something went wrong' });
45
+ }
46
+ });
47
+
48
  // Menjalankan server
49
  app.listen(port, () => {
50
  console.log(`API running on http://localhost:${port}`);
51
+ });