fast72 commited on
Commit
d81b386
·
verified ·
1 Parent(s): 91a5fa8

Create server.js

Browse files
Files changed (1) hide show
  1. server.js +89 -0
server.js ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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);