Fix: Bearbeiten eines Mega-Debrid-Accounts ändert nicht mehr heimlich die API/Web-Bevorzugung
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).
This commit is contained in:
parent
dfd19260f6
commit
1e04b7bdcb
@ -109,7 +109,7 @@ interface MegaDialogAccount {
|
|||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AccountDialogState {
|
export interface AccountDialogState {
|
||||||
mode: "create" | "edit";
|
mode: "create" | "edit";
|
||||||
kind: AccountKind | null;
|
kind: AccountKind | null;
|
||||||
token: string;
|
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) {
|
if (!dialog.kind) {
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
@ -682,7 +682,7 @@ function applyAccountDialogToSettings(settings: AppSettings, dialog: AccountDial
|
|||||||
const firstPassword = megaParsed.length > 0 ? megaParsed[0].password : "";
|
const firstPassword = megaParsed.length > 0 ? megaParsed[0].password : "";
|
||||||
const validIds = new Set(megaParsed.map((a) => a.id));
|
const validIds = new Set(megaParsed.map((a) => a.id));
|
||||||
const megaDebridDisabledAccountIds = (dialog.megaDisabledIds || []).filter((id) => validIds.has(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": {
|
case "megadebrid-web": {
|
||||||
const megaSerialized = serializeMegaDebridAccounts(dialog.megaAccounts);
|
const megaSerialized = serializeMegaDebridAccounts(dialog.megaAccounts);
|
||||||
@ -691,7 +691,7 @@ function applyAccountDialogToSettings(settings: AppSettings, dialog: AccountDial
|
|||||||
const firstPassword = megaParsed.length > 0 ? megaParsed[0].password : "";
|
const firstPassword = megaParsed.length > 0 ? megaParsed[0].password : "";
|
||||||
const validIds = new Set(megaParsed.map((a) => a.id));
|
const validIds = new Set(megaParsed.map((a) => a.id));
|
||||||
const megaDebridDisabledAccountIds = (dialog.megaDisabledIds || []).filter((id) => validIds.has(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":
|
case "bestdebrid-api":
|
||||||
return { ...settings, bestToken: token, bestDebridUseWebLogin: false, providerDailyLimitBytes: nextProviderDailyLimitBytes };
|
return { ...settings, bestToken: token, bestDebridUseWebLogin: false, providerDailyLimitBytes: nextProviderDailyLimitBytes };
|
||||||
|
|||||||
35
tests/account-dialog-prefer-api.test.ts
Normal file
35
tests/account-dialog-prefer-api.test.ts
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user