feat: now the .rar file gets decompressed into the final directory of the game

This commit is contained in:
lilezek 2024-05-06 11:25:13 +02:00
parent 0398164906
commit a748135365
2 changed files with 20 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity
import path from "node:path"; import path from "node:path";
import EasyDL from "easydl"; import EasyDL from "easydl";
import { GameStatus } from "@shared"; import { GameStatus } from "@shared";
import { fullArchive } from "node-7z-archive";
import { Downloader } from "./downloader"; import { Downloader } from "./downloader";
import { RealDebridClient } from "../real-debrid"; import { RealDebridClient } from "../real-debrid";
@ -61,6 +62,23 @@ export class RealDebridDownloader extends Downloader {
}); });
this.download.on("end", async () => { this.download.on("end", async () => {
const updatePayload: QueryDeepPartialEntity<Game> = {
status: GameStatus.Decompressing,
progress: 0.99,
};
await this.updateGameProgress(game.id, updatePayload, {
timeRemaining: 0,
});
this.startDecompression(this.download.savedFilePath!, game);
});
}
static async startDecompression(rarFile: string, game: Game) {
const directory = path.join(game.downloadPath!, game.repack.title);
await fullArchive(rarFile, directory);
const updatePayload: QueryDeepPartialEntity<Game> = { const updatePayload: QueryDeepPartialEntity<Game> = {
status: GameStatus.Finished, status: GameStatus.Finished,
progress: 1, progress: 1,
@ -69,7 +87,6 @@ export class RealDebridDownloader extends Downloader {
await this.updateGameProgress(game.id, updatePayload, { await this.updateGameProgress(game.id, updatePayload, {
timeRemaining: 0, timeRemaining: 0,
}); });
});
} }
static destroy() { static destroy() {

View File

@ -5,6 +5,7 @@ export enum GameStatus {
CheckingFiles = "checking_files", CheckingFiles = "checking_files",
DownloadingMetadata = "downloading_metadata", DownloadingMetadata = "downloading_metadata",
Cancelled = "cancelled", Cancelled = "cancelled",
Decompressing = "decompressing",
Finished = "finished", Finished = "finished",
} }