diff --git a/src/main/events/torrenting/start-game-download.ts b/src/main/events/torrenting/start-game-download.ts index 00978abc..f4db999f 100644 --- a/src/main/events/torrenting/start-game-download.ts +++ b/src/main/events/torrenting/start-game-download.ts @@ -101,6 +101,7 @@ const startGameDownload = async ( await downloadQueueRepository.delete({ game: { id: updatedGame!.id } }); await downloadQueueRepository.insert({ game: { id: updatedGame!.id } }); + await DownloadManager.cancelDownload(updatedGame!.id); await DownloadManager.startDownload(updatedGame!); }; diff --git a/src/main/helpers/index.ts b/src/main/helpers/index.ts index f2b86e5a..b0ff391f 100644 --- a/src/main/helpers/index.ts +++ b/src/main/helpers/index.ts @@ -1,4 +1,5 @@ import axios from "axios"; +import { JSDOM } from "jsdom"; import UserAgent from "user-agents"; export const getSteamAppAsset = ( @@ -48,13 +49,16 @@ export const sleep = (ms: number) => export const requestWebPage = async (url: string) => { const userAgent = new UserAgent(); - return axios + const data = await axios .get(url, { headers: { "User-Agent": userAgent.toString(), }, }) .then((response) => response.data); + + const { window } = new JSDOM(data); + return window.document; }; export const isPortableVersion = () => diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index f97af659..d4733a32 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -6,7 +6,7 @@ import { downloadQueueRepository, gameRepository } from "@main/repository"; import { publishDownloadCompleteNotification } from "../notifications"; import { RealDebridDownloader } from "./real-debrid-downloader"; import type { DownloadProgress } from "@types"; -import { GofileApi } from "../hosters"; +import { GofileApi, QiwiApi } from "../hosters"; import { GenericHttpDownloader } from "./generic-http-downloader"; export class DownloadManager { @@ -96,26 +96,38 @@ export class DownloadManager { } static async startDownload(game: Game) { - if (game.downloader === Downloader.Gofile) { - const id = game!.uri!.split("/").pop(); + switch (game.downloader) { + case Downloader.Gofile: { + const id = game!.uri!.split("/").pop(); - const token = await GofileApi.authorize(); - const downloadLink = await GofileApi.getDownloadLink(id!); + const token = await GofileApi.authorize(); + const downloadLink = await GofileApi.getDownloadLink(id!); - GenericHttpDownloader.startDownload(game, downloadLink, { - Cookie: `accountToken=${token}`, - }); - } else if (game.downloader === Downloader.PixelDrain) { - const id = game!.uri!.split("/").pop(); + GenericHttpDownloader.startDownload(game, downloadLink, { + Cookie: `accountToken=${token}`, + }); + break; + } + case Downloader.PixelDrain: { + const id = game!.uri!.split("/").pop(); - await GenericHttpDownloader.startDownload( - game, - `https://pixeldrain.com/api/file/${id}?download` - ); - } else if (game.downloader === Downloader.Torrent) { - PythonInstance.startDownload(game); - } else if (game.downloader === Downloader.RealDebrid) { - RealDebridDownloader.startDownload(game); + await GenericHttpDownloader.startDownload( + game, + `https://pixeldrain.com/api/file/${id}?download` + ); + break; + } + case Downloader.Qiwi: { + const downloadUrl = await QiwiApi.getDownloadUrl(game.uri!); + + await GenericHttpDownloader.startDownload(game, downloadUrl); + break; + } + case Downloader.Torrent: + PythonInstance.startDownload(game); + break; + case Downloader.RealDebrid: + RealDebridDownloader.startDownload(game); } this.currentDownloader = game.downloader; diff --git a/src/main/services/hosters/index.ts b/src/main/services/hosters/index.ts index 921c45b1..4c5b1803 100644 --- a/src/main/services/hosters/index.ts +++ b/src/main/services/hosters/index.ts @@ -1 +1,2 @@ export * from "./gofile"; +export * from "./qiwi"; diff --git a/src/main/services/how-long-to-beat.ts b/src/main/services/how-long-to-beat.ts index 39b938c5..67e96942 100644 --- a/src/main/services/how-long-to-beat.ts +++ b/src/main/services/how-long-to-beat.ts @@ -1,5 +1,4 @@ import axios from "axios"; -import { JSDOM } from "jsdom"; import { requestWebPage } from "@main/helpers"; import { HowLongToBeatCategory } from "@types"; import { formatName } from "@shared"; @@ -52,10 +51,7 @@ const parseListItems = ($lis: Element[]) => { export const getHowLongToBeatGame = async ( id: string ): Promise => { - const response = await requestWebPage(`https://howlongtobeat.com/game/${id}`); - - const { window } = new JSDOM(response); - const { document } = window; + const document = await requestWebPage(`https://howlongtobeat.com/game/${id}`); const $ul = document.querySelector(".shadow_shadow ul"); if (!$ul) return []; diff --git a/src/renderer/src/constants.ts b/src/renderer/src/constants.ts index 7025df2a..63368c88 100644 --- a/src/renderer/src/constants.ts +++ b/src/renderer/src/constants.ts @@ -7,4 +7,5 @@ export const DOWNLOADER_NAME = { [Downloader.Torrent]: "Torrent", [Downloader.Gofile]: "Gofile", [Downloader.PixelDrain]: "PixelDrain", + [Downloader.Qiwi]: "Qiwi", }; diff --git a/src/renderer/src/pages/game-details/modals/download-settings-modal.css.ts b/src/renderer/src/pages/game-details/modals/download-settings-modal.css.ts index d5655d94..5450378c 100644 --- a/src/renderer/src/pages/game-details/modals/download-settings-modal.css.ts +++ b/src/renderer/src/pages/game-details/modals/download-settings-modal.css.ts @@ -20,13 +20,16 @@ export const hintText = style({ }); export const downloaders = style({ - display: "flex", + display: "grid", gap: `${SPACING_UNIT}px`, + gridTemplateColumns: "repeat(2, 1fr)", }); export const downloaderOption = style({ - flex: "1", position: "relative", + ":only-child": { + gridColumn: "1 / -1", + }, }); export const downloaderIcon = style({ diff --git a/src/shared/index.ts b/src/shared/index.ts index 3ae476ee..28e7315b 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -3,6 +3,7 @@ export enum Downloader { Torrent, Gofile, PixelDrain, + Qiwi, } export enum DownloadSourceStatus { @@ -75,6 +76,7 @@ export const getDownloadersForUri = (uri: string) => { if (uri.startsWith("https://gofile.io")) return [Downloader.Gofile]; if (uri.startsWith("https://pixeldrain.com")) return [Downloader.PixelDrain]; + if (uri.startsWith("https://qiwi.gg")) return [Downloader.Qiwi]; if (realDebridHosts.some((host) => uri.startsWith(host))) return [Downloader.RealDebrid];