Merge branch 'main' into Fix/Datanodes

This commit is contained in:
Shisuys
2025-02-27 00:15:25 -03:00
committed by GitHub
403 changed files with 11605 additions and 8746 deletions

View File

@@ -60,4 +60,12 @@ export class GofileApi {
throw new Error("Failed to get download link");
}
public static async checkDownloadUrl(url: string) {
return axios.head(url, {
headers: {
Cookie: `accountToken=${this.token}`,
},
});
}
}

View File

@@ -1,3 +1,4 @@
export * from "./gofile";
export * from "./qiwi";
export * from "./datanodes";
export * from "./mediafire";

View File

@@ -0,0 +1,54 @@
import fetch from "node-fetch";
export class MediafireApi {
private static readonly validMediafireIdentifierDL = /^[a-zA-Z0-9]+$/m;
private static readonly validMediafirePreDL =
/(?<=['"])(https?:)?(\/\/)?(www\.)?mediafire\.com\/(file|view|download)\/[^'"?]+\?dkey=[^'"]+(?=['"])/;
private static readonly validDynamicDL =
/(?<=['"])https?:\/\/download\d+\.mediafire\.com\/[^'"]+(?=['"])/;
private static readonly checkHTTP = /^https?:\/\//m;
public static async getDownloadUrl(mediafireUrl: string): Promise<string> {
try {
const processedUrl = this.processUrl(mediafireUrl);
const response = await fetch(processedUrl);
if (!response.ok) throw new Error("Failed to fetch Mediafire page");
const html = await response.text();
return this.extractDirectUrl(html);
} catch (error) {
throw new Error(`Failed to get download URL`);
}
}
private static processUrl(url: string): string {
let processed = url.replace("http://", "https://");
if (this.validMediafireIdentifierDL.test(processed)) {
processed = `https://mediafire.com/?${processed}`;
}
if (!this.checkHTTP.test(processed)) {
processed = processed.startsWith("//")
? `https:${processed}`
: `https://${processed}`;
}
return processed;
}
private static extractDirectUrl(html: string): string {
const preMatch = this.validMediafirePreDL.exec(html);
if (preMatch?.[0]) {
return preMatch[0];
}
const dlMatch = this.validDynamicDL.exec(html);
if (dlMatch?.[0]) {
return dlMatch[0];
}
throw new Error("No valid download links found");
}
}