chore: merge with main

This commit is contained in:
Chubby Granny Chaser
2025-02-01 19:59:09 +00:00
6 changed files with 55 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ import { Downloader } from "@shared";
import { WindowManager } from "../window-manager";
import { publishDownloadCompleteNotification } from "../notifications";
import type { Download, DownloadProgress, UserPreferences } from "@types";
import { GofileApi, QiwiApi, DatanodesApi } from "../hosters";
import { GofileApi, QiwiApi, DatanodesApi, MediafireApi } from "../hosters";
import { PythonRPC } from "../python-rpc";
import {
LibtorrentPayload,
@@ -109,7 +109,7 @@ export class DownloadManager {
if (!download || !game) return;
const userPreferences = await db.get<string, UserPreferences>(
const userPreferences = await db.get<string, UserPreferences | null>(
levelKeys.userPreferences,
{
valueEncoding: "json",
@@ -298,6 +298,16 @@ export class DownloadManager {
save_path: download.downloadPath,
};
}
case Downloader.Mediafire: {
const downloadUrl = await MediafireApi.getDownloadUrl(download.uri);
return {
action: "start",
game_id: downloadId,
url: downloadUrl,
save_path: download.downloadPath,
};
}
case Downloader.Torrent:
return {
action: "start",

View File

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

View File

@@ -0,0 +1,39 @@
import axios, { AxiosResponse } from "axios";
import { JSDOM } from "jsdom";
export class MediafireApi {
private static readonly session = axios.create();
public static async getDownloadUrl(mediafireUrl: string): Promise<string> {
const response: AxiosResponse<string> = await this.session.get(
mediafireUrl,
{
headers: {
"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 === 200 || status === 302,
}
);
if (response.status === 302) {
const location = response.headers["location"];
if (!location) {
throw new Error("Missing location header in 302 redirect response");
}
return location;
}
const dom = new JSDOM(response.data);
const downloadButton = dom.window.document.querySelector(
"a#downloadButton"
) as HTMLAnchorElement;
if (!downloadButton?.href) {
throw new Error("Download button URL not found in page content");
}
return downloadButton.href;
}
}