feat: pass headers correctly to downloadURL

This commit is contained in:
Zamitto 2024-08-05 15:21:05 -03:00
parent 070340b34f
commit e1ef8a9193
4 changed files with 18 additions and 9 deletions

View file

@ -26,6 +26,8 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
/* Disconnects libtorrent */
PythonInstance.killTorrent();
HydraApi.handleSignOut();
await Promise.all([
databaseOperations,
HydraApi.post("/auth/logout").catch(() => {}),

View file

@ -45,15 +45,14 @@ export class HTTPDownload {
headers?: Record<string, string>
) {
return new Promise<string>((resolve) => {
WindowManager.mainWindow?.webContents.downloadURL(downloadUrl, {
headers,
});
const options = headers ? { headers } : {};
WindowManager.mainWindow?.webContents.downloadURL(downloadUrl, options);
const gid = ++this.id;
WindowManager.mainWindow?.webContents.session.on(
"will-download",
(_event, item, _webContents) => {
const gid = ++this.id;
this.downloads[gid.toString()] = item;
// Set the save path, making Electron not to prompt a save dialog.

View file

@ -64,6 +64,14 @@ export class HydraApi {
}
}
static handleSignOut() {
this.userAuth = {
authToken: "",
refreshToken: "",
expirationTimestamp: 0,
};
}
static async setupApi() {
this.instance = axios.create({
baseURL: import.meta.env.MAIN_VITE_API_URL,