mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-13 11:42:10 +00:00
feat: update headers
This commit is contained in:
parent
b5b7fe31ae
commit
781e0f4102
3 changed files with 7 additions and 27 deletions
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue