| 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); |