Pubgbc9799 commited on
Commit
985a903
·
verified ·
1 Parent(s): c58abac

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +51 -76
server.js CHANGED
@@ -2,88 +2,63 @@ const express = require('express');
2
  const axios = require('axios');
3
 
4
  const app = express();
5
- const PORT = 7860
6
 
7
- async function terabox(url) {
8
- const terabox = {
9
- api: {
10
- base: "https://teraboxdl.site/api/",
11
- token: "token",
12
- terabox: "terabox"
13
- },
14
- headers: {
15
- 'authority': 'teraboxdl.site',
16
- 'user-agent': 'Postify/1.0.0'
17
- },
18
- token: null
19
- };
20
 
21
- const getToken = async () => {
22
- if (terabox.token) return terabox.token;
23
- try {
24
- const {
25
- data
26
- } = await
27
- axios.get(`${terabox.api.base}${terabox.api.token}`, {
28
- headers:
29
- terabox.headers
30
- });
31
- terabox.token = data.token;
32
- return terabox.token;
33
- } catch (err) {
34
- throw Error(err.message)
35
- };
36
- };
37
 
38
- const isUrl = (url) => {
39
- const match =
40
- url.match(/https?:\/\/(?:www\.)?(?:\w+)\.(com|app)\/s\/([^\/]+)/i);
41
- return match ? `https://1024terabox.com/s/${match[2]}`: null;
42
- };
 
 
43
 
44
- const request = async (endpoint, params = {}) => {
45
- const token = await getToken()
46
- const url = `${terabox.api.base}${endpoint}?` + new URLSearchParams(params);
47
-
48
- try {
49
- const {
50
- data
51
- } = await axios.get(url, {
52
- headers: {
53
- ...terabox.headers,
54
- 'x-access-token': token
55
- }
56
- });
57
- const fileData = data.data?.all_files;
58
- let result = [];
59
- for (let i = 0; i < fileData?.length; i++) {
60
- return {
61
- file_name: fileData[i].file_name,
62
- file_id: fileData[i].fs_id,
63
- size: fileData[i].size,
64
- thumbnail: fileData[i].thumb,
65
- download: fileData[i].download_url,
66
- bytes: fileData[i].sizebytes
67
- }
68
- }
69
- return result;
70
- } catch (err) {
71
- throw Error(err.message)
72
- }
73
- }
74
-
75
- const linkNya = isUrl(url.trim());
76
- return await request(terabox.api.terabox, {
77
- url: linkNya
78
- });
79
  }
80
 
 
 
 
 
 
 
81
  app.all('/dl', async (req, res) => {
82
- const {
83
- url
84
- } = req.body || req.query;
85
- if (/https?:\/\/(?:www\.)?(?:\w+)\.(com|app)\/s\/([^\/]+)/i.test(url) &&
86
- url.includes('tera')) res.json(await terabox(url));
 
 
 
87
  });
88
 
89
- app.listen(PORT);
 
 
 
2
  const axios = require('axios');
3
 
4
  const app = express();
5
+ const PORT = 7860;
6
 
7
+ // JSON parsing enable karein
8
+ app.use(express.json());
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ async function getTeraboxLink(userUrl) {
11
+ try {
12
+ // Short URL se ID nikalne ke liye logic
13
+ const match = userUrl.match(/s\/([^\/]+)/i);
14
+ if (!match) throw new Error("Invalid Terabox Link");
15
+
16
+ const shortId = match[1];
17
+ const cleanUrl = `https://www.1024terabox.com/s/${shortId}`;
 
 
 
 
 
 
 
 
18
 
19
+ // Nayi working API (Arman API)
20
+ const apiRes = await axios.get(`https://terabox-dl-arman.vercel.app/api?url=${cleanUrl}`, {
21
+ headers: {
22
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
23
+ },
24
+ timeout: 10000
25
+ });
26
 
27
+ const data = apiRes.data;
28
+
29
+ // Response format ko check karein aur sahi data return karein
30
+ return {
31
+ file_name: data.file_name || "video.mp4",
32
+ size: data.size || "Unknown",
33
+ download: data.download_url || data.link || data.dlink,
34
+ status: "Success"
35
+ };
36
+ } catch (err) {
37
+ return {
38
+ status: "Error",
39
+ message: "API Blocked or Link Expired",
40
+ details: err.message
41
+ };
42
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
 
45
+ // Home Page par message dikhane ke liye
46
+ app.get('/', (req, res) => {
47
+ res.send("<h1>Terabox API is Running!</h1><p>Use: <code>/dl?url=YOUR_LINK</code></p>");
48
+ });
49
+
50
+ // Download Route
51
  app.all('/dl', async (req, res) => {
52
+ const url = req.query.url || req.body.url;
53
+
54
+ if (!url || !url.includes('tera')) {
55
+ return res.status(400).json({ error: "Please provide a valid Terabox link" });
56
+ }
57
+
58
+ const result = await getTeraboxLink(url);
59
+ res.json(result);
60
  });
61
 
62
+ app.listen(PORT, () => {
63
+ console.log(`Server started on port ${PORT}`);
64
+ });