OhMyDitzzy
commited on
Commit
Β·
8dc4abf
1
Parent(s):
81ee18d
Add terabox downloader
Browse files- package.json +2 -0
- src/server/plugins/downloader/terabox.js +192 -0
package.json
CHANGED
|
@@ -38,9 +38,11 @@
|
|
| 38 |
"@radix-ui/react-tabs": "^1.1.13",
|
| 39 |
"@upstash/redis": "^1.36.1",
|
| 40 |
"axios": "^1.13.2",
|
|
|
|
| 41 |
"class-variance-authority": "^0.7.1",
|
| 42 |
"clsx": "^2.1.1",
|
| 43 |
"express": "^5.2.1",
|
|
|
|
| 44 |
"framer-motion": "^12.26.2",
|
| 45 |
"lucide-react": "^0.562.0",
|
| 46 |
"prismjs": "^1.30.0",
|
|
|
|
| 38 |
"@radix-ui/react-tabs": "^1.1.13",
|
| 39 |
"@upstash/redis": "^1.36.1",
|
| 40 |
"axios": "^1.13.2",
|
| 41 |
+
"cheerio": "^1.1.2",
|
| 42 |
"class-variance-authority": "^0.7.1",
|
| 43 |
"clsx": "^2.1.1",
|
| 44 |
"express": "^5.2.1",
|
| 45 |
+
"form-data": "^4.0.5",
|
| 46 |
"framer-motion": "^12.26.2",
|
| 47 |
"lucide-react": "^0.562.0",
|
| 48 |
"prismjs": "^1.30.0",
|
src/server/plugins/downloader/terabox.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import axios from "axios";
|
| 2 |
+
import FormData from "form-data";
|
| 3 |
+
import * as cheerio from "cheerio";
|
| 4 |
+
import { sendSuccess, ErrorResponses } from "../../lib/response-helper.js";
|
| 5 |
+
|
| 6 |
+
class TeraBox {
|
| 7 |
+
constructor() {
|
| 8 |
+
this.BASE_URL = "https://terabxdownloader.org";
|
| 9 |
+
this.AJAX_PATH = "/wp-admin/admin-ajax.php";
|
| 10 |
+
this.HEADERS = {
|
| 11 |
+
"accept": "*/*",
|
| 12 |
+
"accept-language": "id-ID",
|
| 13 |
+
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
| 14 |
+
"Referer": "https://terabxdownloader.org/",
|
| 15 |
+
"Referrer-Policy": "strict-origin-when-cross-origin"
|
| 16 |
+
};
|
| 17 |
+
this.CREATED_BY = "Ditzzy";
|
| 18 |
+
this.NOTE = "Thank you for using this scrape, I hope you appreciate me for making this scrape by not deleting wm";
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
wrapResponse(data) {
|
| 22 |
+
return {
|
| 23 |
+
created_by: this.CREATED_BY,
|
| 24 |
+
note: this.NOTE,
|
| 25 |
+
results: data
|
| 26 |
+
};
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
transformFolder(rawFolder) {
|
| 30 |
+
return {
|
| 31 |
+
name: rawFolder["π Name"],
|
| 32 |
+
type: rawFolder["π Type"],
|
| 33 |
+
size: rawFolder["π Size"]
|
| 34 |
+
};
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
transformFile(rawFile) {
|
| 38 |
+
return {
|
| 39 |
+
name: rawFile["π Name"],
|
| 40 |
+
type: rawFile["π Type"],
|
| 41 |
+
fullPath: rawFile["π Full Path"],
|
| 42 |
+
size: rawFile["π Size"],
|
| 43 |
+
downloadLink: rawFile["π½ Direct Download Link"]
|
| 44 |
+
};
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
transformSummary(rawSummary) {
|
| 48 |
+
return {
|
| 49 |
+
totalFolders: rawSummary["π Total Folders"],
|
| 50 |
+
totalFiles: rawSummary["π Total Files"],
|
| 51 |
+
totalItems: rawSummary["π’ Total Items"]
|
| 52 |
+
};
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
extractData(rawResponse) {
|
| 56 |
+
const rawData = rawResponse.data;
|
| 57 |
+
|
| 58 |
+
return {
|
| 59 |
+
folders: (rawData["π Folders"] || []).map(folder => this.transformFolder(folder)),
|
| 60 |
+
files: (rawData["π Files"] || []).map(file => this.transformFile(file)),
|
| 61 |
+
summary: rawData["π Summary"]
|
| 62 |
+
? this.transformSummary(rawData["π Summary"])
|
| 63 |
+
: { totalFolders: 0, totalFiles: 0, totalItems: 0 },
|
| 64 |
+
shortlink: rawData["π ShortLink"] || ""
|
| 65 |
+
};
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
async getNonce() {
|
| 69 |
+
const { data } = await axios.get(this.BASE_URL);
|
| 70 |
+
|
| 71 |
+
const $ = cheerio.load(data);
|
| 72 |
+
const nncSc = $('#jquery-core-js-extra').html();
|
| 73 |
+
|
| 74 |
+
if (!nncSc) {
|
| 75 |
+
throw new Error("Nonce script not found, Unable to continue.");
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
const match = nncSc.match(/"nonce"\s*:\s*"([^"]+)"/i);
|
| 79 |
+
|
| 80 |
+
if (!match) {
|
| 81 |
+
throw new Error('Nonce script found but Nonce value could not be found');
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
return match[1];
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
async download(url) {
|
| 88 |
+
try {
|
| 89 |
+
const nonce = await this.getNonce();
|
| 90 |
+
|
| 91 |
+
const form = new FormData();
|
| 92 |
+
form.append('action', 'terabox_fetch');
|
| 93 |
+
form.append('url', url);
|
| 94 |
+
form.append('nonce', nonce);
|
| 95 |
+
|
| 96 |
+
const config = {
|
| 97 |
+
url: this.BASE_URL + this.AJAX_PATH,
|
| 98 |
+
method: "POST",
|
| 99 |
+
headers: this.HEADERS,
|
| 100 |
+
data: form
|
| 101 |
+
};
|
| 102 |
+
|
| 103 |
+
const { data } = await axios.request(config);
|
| 104 |
+
const extractedData = this.extractData(data);
|
| 105 |
+
|
| 106 |
+
return this.wrapResponse(extractedData);
|
| 107 |
+
} catch (e) {
|
| 108 |
+
throw new Error(`Error downloading from TeraBox: ${e instanceof Error ? e.message : String(e)}`);
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
/** @type {import("../../types/plugin").ApiPluginHandler} */
|
| 114 |
+
const handler = {
|
| 115 |
+
name: "Terabox Downloader",
|
| 116 |
+
description: "Download terabox files or folders",
|
| 117 |
+
version: "1.0.0",
|
| 118 |
+
method: "GET",
|
| 119 |
+
category: ["downloader"],
|
| 120 |
+
alias: ["terabox"],
|
| 121 |
+
tags: ["downloader"],
|
| 122 |
+
parameters: {
|
| 123 |
+
query: [
|
| 124 |
+
{
|
| 125 |
+
name: "url",
|
| 126 |
+
type: "string",
|
| 127 |
+
required: true,
|
| 128 |
+
description: "Your Terabox URL",
|
| 129 |
+
example: "https://1024terabox.com/s/1hTspAuZCdy5vDAPiUOn3ig"
|
| 130 |
+
}
|
| 131 |
+
],
|
| 132 |
+
body: [],
|
| 133 |
+
headers: []
|
| 134 |
+
},
|
| 135 |
+
responses: {
|
| 136 |
+
200: {
|
| 137 |
+
status: 200,
|
| 138 |
+
description: "Successfully retrieved Terabox data",
|
| 139 |
+
example: {
|
| 140 |
+
status: 200,
|
| 141 |
+
author: "Ditzzy",
|
| 142 |
+
note: "Thank you for using this API!",
|
| 143 |
+
results: {}
|
| 144 |
+
}
|
| 145 |
+
},
|
| 146 |
+
400: {
|
| 147 |
+
status: 400,
|
| 148 |
+
description: "Invalid Terabox URL provided",
|
| 149 |
+
example: {
|
| 150 |
+
status: 400,
|
| 151 |
+
message: "Invalid URL - must be a valid Terabox URL"
|
| 152 |
+
}
|
| 153 |
+
},
|
| 154 |
+
404: {
|
| 155 |
+
status: 404,
|
| 156 |
+
description: "Missing required parameter",
|
| 157 |
+
example: {
|
| 158 |
+
status: 404,
|
| 159 |
+
message: "Missing required parameter: ..."
|
| 160 |
+
}
|
| 161 |
+
},
|
| 162 |
+
500: {
|
| 163 |
+
status: 500,
|
| 164 |
+
description: "Server error or Terabox API unavailable",
|
| 165 |
+
example: {
|
| 166 |
+
status: 500,
|
| 167 |
+
message: "An error occurred, please try again later."
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
},
|
| 171 |
+
exec: async (req, res) => {
|
| 172 |
+
const { url } = req.query
|
| 173 |
+
|
| 174 |
+
if (!url) return ErrorResponses.missingParameter(res, "url");
|
| 175 |
+
|
| 176 |
+
const regex = /^(https?:\/\/)?(www\.)?(terabox\.com|teraboxapp\.com|1024tera\.com|1024terabox\.com|terabox\.app|nephobox\.com)\/(s\/|sharing\/embed\?surl=)[\w-]+/i
|
| 177 |
+
|
| 178 |
+
if (!regex.test(url)) return ErrorResponses.invalidUrl(res, "Invalid URL - must be a valid Terabox URL");
|
| 179 |
+
|
| 180 |
+
const terabox = new TeraBox();
|
| 181 |
+
try {
|
| 182 |
+
const download = await terabox.download(url);
|
| 183 |
+
|
| 184 |
+
return sendSuccess(res, download.results);
|
| 185 |
+
} catch (e) {
|
| 186 |
+
console.error("Terabox download error:", e);
|
| 187 |
+
return ErrorResponses.serverError(res);
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
export default handler;
|