Merge branch 'feat/migration-to-leveldb' into feature/torbox-integration

# Conflicts:
#	src/renderer/src/constants.ts
#	src/shared/constants.ts
This commit is contained in:
Zamitto 2025-02-01 17:03:14 -03:00
commit 7fbaea15e8
7 changed files with 60 additions and 3 deletions

View File

@ -2,7 +2,7 @@ import { Downloader } from "@shared";
import { WindowManager } from "../window-manager"; import { WindowManager } from "../window-manager";
import { publishDownloadCompleteNotification } from "../notifications"; import { publishDownloadCompleteNotification } from "../notifications";
import type { Download, DownloadProgress, UserPreferences } from "@types"; 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 { PythonRPC } from "../python-rpc";
import { import {
LibtorrentPayload, LibtorrentPayload,
@ -111,7 +111,7 @@ export class DownloadManager {
if (!download || !game) return; if (!download || !game) return;
const userPreferences = await db.get<string, UserPreferences>( const userPreferences = await db.get<string, UserPreferences | null>(
levelKeys.userPreferences, levelKeys.userPreferences,
{ {
valueEncoding: "json", valueEncoding: "json",
@ -306,6 +306,16 @@ export class DownloadManager {
save_path: download.downloadPath, 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: case Downloader.Torrent:
return { return {
action: "start", action: "start",

View File

@ -1,3 +1,4 @@
export * from "./gofile"; export * from "./gofile";
export * from "./qiwi"; export * from "./qiwi";
export * from "./datanodes"; 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;
}
}

View File

@ -19,6 +19,7 @@ import { db, gamesSublevel, levelKeys } from "@main/level";
import { slice, sortBy } from "lodash-es"; import { slice, sortBy } from "lodash-es";
import type { UserPreferences } from "@types"; import type { UserPreferences } from "@types";
import { AuthPage } from "@shared"; import { AuthPage } from "@shared";
import { isStaging } from "@main/constants";
export class WindowManager { export class WindowManager {
public static mainWindow: Electron.BrowserWindow | null = null; public static mainWindow: Electron.BrowserWindow | null = null;
@ -172,7 +173,9 @@ export class WindowManager {
authWindow.removeMenu(); authWindow.removeMenu();
if (!app.isPackaged) authWindow.webContents.openDevTools(); if (!app.isPackaged || isStaging) {
authWindow.webContents.openDevTools();
}
authWindow.loadURL( authWindow.loadURL(
`${import.meta.env.MAIN_VITE_AUTH_URL}${page}?${searchParams.toString()}` `${import.meta.env.MAIN_VITE_AUTH_URL}${page}?${searchParams.toString()}`

View File

@ -9,6 +9,7 @@ export const DOWNLOADER_NAME = {
[Downloader.PixelDrain]: "PixelDrain", [Downloader.PixelDrain]: "PixelDrain",
[Downloader.Qiwi]: "Qiwi", [Downloader.Qiwi]: "Qiwi",
[Downloader.Datanodes]: "Datanodes", [Downloader.Datanodes]: "Datanodes",
[Downloader.Mediafire]: "Mediafire",
[Downloader.TorBox]: "TorBox", [Downloader.TorBox]: "TorBox",
}; };

View File

@ -5,6 +5,7 @@ export enum Downloader {
PixelDrain, PixelDrain,
Qiwi, Qiwi,
Datanodes, Datanodes,
Mediafire,
TorBox, TorBox,
} }

View File

@ -88,6 +88,8 @@ export const getDownloadersForUri = (uri: string) => {
if (uri.startsWith("https://pixeldrain.com")) return [Downloader.PixelDrain]; if (uri.startsWith("https://pixeldrain.com")) return [Downloader.PixelDrain];
if (uri.startsWith("https://qiwi.gg")) return [Downloader.Qiwi]; if (uri.startsWith("https://qiwi.gg")) return [Downloader.Qiwi];
if (uri.startsWith("https://datanodes.to")) return [Downloader.Datanodes]; if (uri.startsWith("https://datanodes.to")) return [Downloader.Datanodes];
if (uri.startsWith("https://www.mediafire.com"))
return [Downloader.Mediafire];
if (realDebridHosts.some((host) => uri.startsWith(host))) if (realDebridHosts.some((host) => uri.startsWith(host)))
return [Downloader.RealDebrid]; return [Downloader.RealDebrid];