Update mediafire.ts

This commit is contained in:
Shisuys 2025-02-01 19:54:31 -03:00
parent 3aa0b8fa6c
commit a126707fb7

View File

@ -6,7 +6,7 @@ export class MediafireApi {
private static readonly validMediafirePreDL = private static readonly validMediafirePreDL =
/(?<=['"])(https?:)?(\/\/)?(www\.)?mediafire\.com\/(file|view|download)\/[^'"?]+\?dkey=[^'"]+(?=['"])/; /(?<=['"])(https?:)?(\/\/)?(www\.)?mediafire\.com\/(file|view|download)\/[^'"?]+\?dkey=[^'"]+(?=['"])/;
private static readonly validDynamicDL = private static readonly validDynamicDL =
/(?<=['"])https?:\/\/download[0-9]+\.mediafire\.com\/[^'"]+(?=['"])/; /(?<=['"])https?:\/\/download\d+\.mediafire\.com\/[^'"]+(?=['"])/;
private static readonly checkHTTP = /^https?:\/\//m; private static readonly checkHTTP = /^https?:\/\//m;
public static async getDownloadUrl(mediafireUrl: string): Promise<string> { public static async getDownloadUrl(mediafireUrl: string): Promise<string> {
@ -19,7 +19,7 @@ export class MediafireApi {
if (!response.ok) throw new Error("Failed to fetch Mediafire page"); if (!response.ok) throw new Error("Failed to fetch Mediafire page");
const html = await response.text(); const html = await response.text();
return this.extractDirectUrl(html, processedUrl); return this.extractDirectUrl(html);
} catch (error) { } catch (error) {
throw new Error(`Failed to get download URL: ${error.message}`); throw new Error(`Failed to get download URL: ${error.message}`);
} }
@ -42,14 +42,14 @@ export class MediafireApi {
} }
private static extractDirectUrl(html: string): string { private static extractDirectUrl(html: string): string {
const preUrls = html.match(this.validMediafirePreDL); const preMatch = this.validMediafirePreDL.exec(html);
if (preUrls && preUrls[0]) { if (preMatch?.[0]) {
return preUrls[0]; return preMatch[0];
} }
const dlUrls = html.match(this.validDynamicDL); const dlMatch = this.validDynamicDL.exec(html);
if (dlUrls && dlUrls[0]) { if (dlMatch?.[0]) {
return dlUrls[0]; return dlMatch[0];
} }
throw new Error("No valid download links found"); throw new Error("No valid download links found");