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

View File

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