Update datanodes.ts

This commit is contained in:
Shisuys 2025-01-05 17:32:09 -03:00
parent 82b1d710c2
commit 2a31c32cda

View File

@ -1,7 +1,7 @@
import axios, { AxiosResponse } from "axios"; import axios, { AxiosResponse } from "axios";
export class DatanodesApi { export class DatanodesApi {
private static session = axios.create({}); private static readonly session = axios.create({});
public static async getDownloadUrl(downloadUrl: string): Promise<string> { public static async getDownloadUrl(downloadUrl: string): Promise<string> {
const parsedUrl = new URL(downloadUrl); const parsedUrl = new URL(downloadUrl);
@ -10,16 +10,6 @@ export class DatanodesApi {
const fileCode = decodeURIComponent(pathSegments[1]); const fileCode = decodeURIComponent(pathSegments[1]);
const fileName = decodeURIComponent(pathSegments[pathSegments.length - 1]); const fileName = decodeURIComponent(pathSegments[pathSegments.length - 1]);
const headers: Record<string, string> = {
"Content-Type": "application/x-www-form-urlencoded",
Cookie: `lang=english; file_name=${fileName}; file_code=${fileCode};`,
Host: "datanodes.to",
Origin: "https://datanodes.to",
Referer: "https://datanodes.to/download",
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
};
const payload = new URLSearchParams({ const payload = new URLSearchParams({
op: "download2", op: "download2",
id: fileCode, id: fileCode,
@ -30,16 +20,21 @@ export class DatanodesApi {
adblock_detected: "", adblock_detected: "",
}); });
const config = { const response: AxiosResponse = await this.session.post(
headers,
maxRedirects: 0,
validateStatus: (status: number) => status === 302 || status < 400,
};
const response: AxiosResponse = await DatanodesApi.session.post(
"https://datanodes.to/download", "https://datanodes.to/download",
payload, payload,
config {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Cookie: `lang=english; file_name=${fileName}; file_code=${fileCode};`,
Host: "datanodes.to",
Origin: "https://datanodes.to",
Referer: "https://datanodes.to/download",
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
},
maxRedirects: 0, validateStatus: (status: number) => status === 302 || status < 400,
}
); );
if (response.status === 302) { if (response.status === 302) {