File size: 1,927 Bytes
d81b386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const express = require('express');
const axios = require('axios');

const app = express();
const PORT = 7860

async function terabox(url) {
	const terabox = {
		api: {
			base: "https://teraboxdl.site/api/",
			token: "token",
			terabox: "terabox"
		},
		headers: {
			'authority': 'teraboxdl.site',
			'user-agent': 'Postify/1.0.0'
		},
		token: null
	};

	const getToken = async () => {
		if (terabox.token) return terabox.token;
		try {
			const {
				data
			} = await
			axios.get(`${terabox.api.base}${terabox.api.token}`, {
				headers:
				terabox.headers
			});
			terabox.token = data.token;
			return terabox.token;
		} catch (err) {
			throw Error(err.message)
		};
	};

	const isUrl = (url) => {
		const match =
		url.match(/https?:\/\/(?:www\.)?(?:\w+)\.(com|app)\/s\/([^\/]+)/i);
		return match ? `https://1024terabox.com/s/${match[2]}`: null;
	};

	const request = async (endpoint, params = {}) => {
		const token = await getToken()
		const url = `${terabox.api.base}${endpoint}?` + new URLSearchParams(params);

		try {
			const {
				data
			} = await axios.get(url, {
					headers: {
						...terabox.headers,
						'x-access-token': token
					}
				});
			const fileData = data.data?.all_files;
			let result = [];
			for (let i = 0; i < fileData?.length; i++) {
				return {
					file_name: fileData[i].file_name,
					file_id: fileData[i].fs_id,
					size: fileData[i].size,
					thumbnail: fileData[i].thumb,
					download: fileData[i].download_url,
					bytes: fileData[i].sizebytes
				}
			}
			return result;
		} catch (err) {
			throw Error(err.message)
		}
	}

	const linkNya = isUrl(url.trim());
	return await request(terabox.api.terabox, {
		url: linkNya
	});
}

app.all('/dl', async (req, res) => {
	const {
		url
	} = req.body || req.query;
	if (/https?:\/\/(?:www\.)?(?:\w+)\.(com|app)\/s\/([^\/]+)/i.test(url) &&
		url.includes('tera')) res.json(await terabox(url));
});

app.listen(PORT);