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, "<<<");
GenericHTTPDownloader.startDownload(game, downloadLink, [
`Cookie: accountToken=${token}`,
]);
GenericHTTPDownloader.startDownload(game, downloadLink, {
Cookie: `accountToken=${token}`,
});
} else if (game.downloader === Downloader.PixelDrain) {
const id = game!.uri!.split("/").pop();

View file

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

View file

@ -26,7 +26,7 @@ export class HTTPDownload {
static async cancelDownload(gid: string) {
const downloadItem: DownloadItem = this.downloads[gid];
downloadItem?.cancel();
this.downloads;
delete this.downloads[gid];
}
static async pauseDownload(gid: string) {
@ -42,11 +42,11 @@ export class HTTPDownload {
static async startDownload(
downloadPath: string,
downloadUrl: string,
header: string[] = []
headers?: Record<string, string>
) {
return new Promise<string>((resolve) => {
WindowManager.mainWindow?.webContents.downloadURL(downloadUrl, {
headers: { Cookie: header[0].split(": ")[1] },
headers,
});
WindowManager.mainWindow?.webContents.session.on(
@ -59,26 +59,6 @@ export class HTTPDownload {
// Set the save path, making Electron not to prompt a save dialog.
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());
}
);