From 1e04b7bdcb9cec16e5276df6ed1e655cc69042c6 Mon Sep 17 00:00:00 2001 From: Sucukdeluxe Date: Wed, 17 Jun 2026 05:54:42 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Bearbeiten=20eines=20Mega-Debrid-Account?= =?UTF-8?q?s=20=C3=A4ndert=20nicht=20mehr=20heimlich=20die=20API/Web-Bevor?= =?UTF-8?q?zugung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sind beide Mega-Debrid-Modi (API + Web) aktiv, entscheidet megaDebridPreferApi, welcher Modus zuerst versucht wird. Beim Speichern des Account-Dialogs hat applyAccountDialogToSettings diese Einstellung jedoch fest überschrieben: ein Bearbeiten der API-Zeile erzwang megaDebridPreferApi=true, ein Bearbeiten der Web-Zeile erzwang false. Wer also bewusst Web bevorzugt (preferApi=false) hatte und nur einen zweiten Account hinzufügen oder das Tageslimit ändern wollte und dafür die API-Zeile bearbeitete, dem wurde die Reihenfolge ungefragt auf "API zuerst" umgestellt — was die Provider-Auflösung für alle künftigen Mega-Links ändert. Fix: Die festen megaDebridPreferApi-Werte aus beiden Dialog-Zweigen entfernt. Der bestehende Wert wird über den ...settings-Spread durchgereicht. Erst-Anlage bleibt korrekt, weil der Default ohnehin true ist (constants). Bei nur EINEM aktiven Modus ist preferApi ohnehin irrelevant (die single-mode-Zweige kurzschließen davor). Test: bei beiden Modi aktiv + preferApi=false bleibt nach API-Edit false; bei preferApi=true bleibt nach Web-Edit true. Mit der alten Festverdrahtung kippt der Wert (rot bewiesen). --- src/renderer/App.tsx | 8 +++--- tests/account-dialog-prefer-api.test.ts | 35 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tests/account-dialog-prefer-api.test.ts diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 804c636..c37cfea 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -109,7 +109,7 @@ interface MegaDialogAccount { password: string; } -interface AccountDialogState { +export interface AccountDialogState { mode: "create" | "edit"; kind: AccountKind | null; token: string; @@ -647,7 +647,7 @@ function createAccountDialogState(mode: "create" | "edit", kind: AccountKind | n } } -function applyAccountDialogToSettings(settings: AppSettings, dialog: AccountDialogState): AppSettings { +export function applyAccountDialogToSettings(settings: AppSettings, dialog: AccountDialogState): AppSettings { if (!dialog.kind) { return settings; } @@ -682,7 +682,7 @@ function applyAccountDialogToSettings(settings: AppSettings, dialog: AccountDial const firstPassword = megaParsed.length > 0 ? megaParsed[0].password : ""; const validIds = new Set(megaParsed.map((a) => a.id)); const megaDebridDisabledAccountIds = (dialog.megaDisabledIds || []).filter((id) => validIds.has(id)); - return { ...settings, megaCredentials: megaSerialized, megaLogin: firstLogin, megaPassword: firstPassword, megaDebridApiEnabled: true, megaDebridPreferApi: true, megaDebridDisabledAccountIds, providerDailyLimitBytes: nextProviderDailyLimitBytes }; + return { ...settings, megaCredentials: megaSerialized, megaLogin: firstLogin, megaPassword: firstPassword, megaDebridApiEnabled: true, megaDebridDisabledAccountIds, providerDailyLimitBytes: nextProviderDailyLimitBytes }; } case "megadebrid-web": { const megaSerialized = serializeMegaDebridAccounts(dialog.megaAccounts); @@ -691,7 +691,7 @@ function applyAccountDialogToSettings(settings: AppSettings, dialog: AccountDial const firstPassword = megaParsed.length > 0 ? megaParsed[0].password : ""; const validIds = new Set(megaParsed.map((a) => a.id)); const megaDebridDisabledAccountIds = (dialog.megaDisabledIds || []).filter((id) => validIds.has(id)); - return { ...settings, megaCredentials: megaSerialized, megaLogin: firstLogin, megaPassword: firstPassword, megaDebridWebEnabled: true, megaDebridPreferApi: false, megaDebridDisabledAccountIds, providerDailyLimitBytes: nextProviderDailyLimitBytes }; + return { ...settings, megaCredentials: megaSerialized, megaLogin: firstLogin, megaPassword: firstPassword, megaDebridWebEnabled: true, megaDebridDisabledAccountIds, providerDailyLimitBytes: nextProviderDailyLimitBytes }; } case "bestdebrid-api": return { ...settings, bestToken: token, bestDebridUseWebLogin: false, providerDailyLimitBytes: nextProviderDailyLimitBytes }; diff --git a/tests/account-dialog-prefer-api.test.ts b/tests/account-dialog-prefer-api.test.ts new file mode 100644 index 0000000..bf57c79 --- /dev/null +++ b/tests/account-dialog-prefer-api.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, it } from "vitest"; +import { applyAccountDialogToSettings, AccountDialogState } from "../src/renderer/App"; +import { defaultSettings } from "../src/main/constants"; + +function megaDialog(kind: "megadebrid-api" | "megadebrid-web"): AccountDialogState { + return { + mode: "edit", + kind, + token: "", + login: "", + password: "", + dailyLimitGb: "", + keyDailyLimitGbById: {}, + megaAccounts: [{ login: "user@x", password: "pw" }], + megaNewLogin: "", + megaNewPassword: "", + megaDisabledIds: [] + }; +} + +describe("applyAccountDialogToSettings — keeps the user's Mega preferApi choice", () => { + it("does not flip megaDebridPreferApi to true when editing the API account", () => { + const settings = { ...defaultSettings(), megaDebridApiEnabled: true, megaDebridWebEnabled: true, megaDebridPreferApi: false }; + const next = applyAccountDialogToSettings(settings, megaDialog("megadebrid-api")); + expect(next.megaDebridApiEnabled).toBe(true); + expect(next.megaDebridPreferApi).toBe(false); + }); + + it("does not flip megaDebridPreferApi to false when editing the Web account", () => { + const settings = { ...defaultSettings(), megaDebridApiEnabled: true, megaDebridWebEnabled: true, megaDebridPreferApi: true }; + const next = applyAccountDialogToSettings(settings, megaDialog("megadebrid-web")); + expect(next.megaDebridWebEnabled).toBe(true); + expect(next.megaDebridPreferApi).toBe(true); + }); +});