feat: update headers

This commit is contained in:
Zamitto 2024-07-15 22:29:34 -03:00
parent b5b7fe31ae
commit 781e0f4102
3 changed files with 7 additions and 27 deletions

View file

@ -104,9 +104,9 @@ export class DownloadManager {
console.log(downloadLink, token, "<<<"); console.log(downloadLink, token, "<<<");
GenericHTTPDownloader.startDownload(game, downloadLink, [ GenericHTTPDownloader.startDownload(game, downloadLink, {
`Cookie: accountToken=${token}`, Cookie: `accountToken=${token}`,
]); });
} else if (game.downloader === Downloader.PixelDrain) { } else if (game.downloader === Downloader.PixelDrain) {
const id = game!.uri!.split("/").pop(); const id = game!.uri!.split("/").pop();

View file

@ -69,7 +69,7 @@ export class GenericHTTPDownloader {
static async startDownload( static async startDownload(
game: Game, game: Game,
downloadUrl: string, downloadUrl: string,
headers: string[] = [] headers?: Record<string, string>
) { ) {
this.downloadingGame = game; this.downloadingGame = game;

View file

@ -26,7 +26,7 @@ export class HTTPDownload {
static async cancelDownload(gid: string) { static async cancelDownload(gid: string) {
const downloadItem: DownloadItem = this.downloads[gid]; const downloadItem: DownloadItem = this.downloads[gid];
downloadItem?.cancel(); downloadItem?.cancel();
this.downloads; delete this.downloads[gid];
} }
static async pauseDownload(gid: string) { static async pauseDownload(gid: string) {
@ -42,11 +42,11 @@ export class HTTPDownload {
static async startDownload( static async startDownload(
downloadPath: string, downloadPath: string,
downloadUrl: string, downloadUrl: string,
header: string[] = [] headers?: Record<string, string>
) { ) {
return new Promise<string>((resolve) => { return new Promise<string>((resolve) => {
WindowManager.mainWindow?.webContents.downloadURL(downloadUrl, { WindowManager.mainWindow?.webContents.downloadURL(downloadUrl, {
headers: { Cookie: header[0].split(": ")[1] }, headers,
}); });
WindowManager.mainWindow?.webContents.session.on( WindowManager.mainWindow?.webContents.session.on(
@ -59,26 +59,6 @@ export class HTTPDownload {
// Set the save path, making Electron not to prompt a save dialog. // Set the save path, making Electron not to prompt a save dialog.
item.setSavePath(downloadPath); item.setSavePath(downloadPath);
item.on("updated", (_event, state) => {
if (state === "interrupted") {
console.log("Download is interrupted but can be resumed");
} else if (state === "progressing") {
if (item.isPaused()) {
console.log("Download is paused");
} else {
console.log(`Received bytes: ${item.getReceivedBytes()}`);
}
}
});
item.once("done", (_event, state) => {
if (state === "completed") {
console.log("Download successfully");
} else {
console.log(`Download failed: ${state}`);
}
});
resolve(gid.toString()); resolve(gid.toString());
} }
); );