fix: real debrid decompression happens in a folder that hydra recognises properly.

This commit is contained in:
lilezek 2024-04-30 11:11:58 +02:00
parent c5693e94af
commit 7ee5b73688
2 changed files with 13 additions and 7 deletions

View File

@ -10,6 +10,7 @@ import { TorrentUpdate } from "./torrent-client";
import { HTTPDownloader } from "./http-downloader"; import { HTTPDownloader } from "./http-downloader";
import { Unrar } from "../unrar"; import { Unrar } from "../unrar";
import { GameStatus } from "@globals"; import { GameStatus } from "@globals";
import path from 'node:path';
interface DownloadStatus { interface DownloadStatus {
numPeers: number; numPeers: number;
@ -23,7 +24,7 @@ export class Downloader {
static async usesRealDebrid() { static async usesRealDebrid() {
const userPreferences = await userPreferencesRepository.findOne({ where: { id: 1 } }); const userPreferences = await userPreferencesRepository.findOne({ where: { id: 1 } });
return userPreferences.realDebridApiToken !== null; return userPreferences!.realDebridApiToken !== null;
} }
static async cancelDownload() { static async cancelDownload() {
@ -72,7 +73,7 @@ export class Downloader {
const { links } = await RealDebridClient.getInfo(torrent.id); const { links } = await RealDebridClient.getInfo(torrent.id);
const { download } = await RealDebridClient.unrestrictLink(links[0]); const { download } = await RealDebridClient.unrestrictLink(links[0]);
this.lastHttpDownloader = new HTTPDownloader(); this.lastHttpDownloader = new HTTPDownloader();
this.lastHttpDownloader.download(download, game.downloadPath, game.id); this.lastHttpDownloader.download(download, game.downloadPath!, game.id);
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -102,14 +103,14 @@ export class Downloader {
body: t("game_ready_to_install", { body: t("game_ready_to_install", {
ns: "notifications", ns: "notifications",
lng: userPreferences.language, lng: userPreferences.language,
title: game.title, title: game?.title,
}), }),
}).show(); }).show();
} }
} }
if (gameUpdate.decompressionProgress === 0 && gameUpdate.status === GameStatus.Decompressing) { if (game && gameUpdate.decompressionProgress === 0 && gameUpdate.status === GameStatus.Decompressing) {
const unrar = await Unrar.fromFilePath(game.rarPath, game.downloadPath); const unrar = await Unrar.fromFilePath(game.rarPath!, path.join(game.downloadPath!, game.folderName!));
unrar.extract(); unrar.extract();
this.updateGameProgress(gameId, { this.updateGameProgress(gameId, {
decompressionProgress: 1, decompressionProgress: 1,
@ -117,7 +118,7 @@ export class Downloader {
}, downloadStatus); }, downloadStatus);
} }
if (WindowManager.mainWindow) { if (WindowManager.mainWindow && game) {
const progress = this.getGameProgress(game); const progress = this.getGameProgress(game);
WindowManager.mainWindow.setProgressBar(progress === 1 ? -1 : progress); WindowManager.mainWindow.setProgressBar(progress === 1 ? -1 : progress);

View File

@ -5,6 +5,10 @@ import { WindowManager } from '../window-manager';
import { Downloader } from './downloader'; import { Downloader } from './downloader';
import { GameStatus } from '@globals'; import { GameStatus } from '@globals';
function dropExtension(fileName: string) {
return fileName.split('.').slice(0, -1).join('.');
}
export class HTTPDownloader { export class HTTPDownloader {
private downloadManager: ElectronDownloadManager; private downloadManager: ElectronDownloadManager;
private downloadId: string | null = null; private downloadId: string | null = null;
@ -18,7 +22,7 @@ export class HTTPDownloader {
this.downloadId = await this.downloadManager.download({ this.downloadId = await this.downloadManager.download({
url, url,
window: window, window: window!,
callbacks: { callbacks: {
onDownloadStarted: async (ev) => { onDownloadStarted: async (ev) => {
const updatePayload: QueryDeepPartialEntity<Game> = { const updatePayload: QueryDeepPartialEntity<Game> = {
@ -27,6 +31,7 @@ export class HTTPDownloader {
bytesDownloaded: 0, bytesDownloaded: 0,
fileSize: ev.item.getTotalBytes(), fileSize: ev.item.getTotalBytes(),
rarPath: `${destination}/.rd/${ev.resolvedFilename}`, rarPath: `${destination}/.rd/${ev.resolvedFilename}`,
folderName: dropExtension(ev.resolvedFilename)
}; };
const downloadStatus = { const downloadStatus = {
numPeers: 0, numPeers: 0,