Skip to content

Commit 9d0a2fb

Browse files
authored
fix: load subsection sub-option defaults (#944)
fix(presets/newznab): set appropriate fallbacks for singleIp and showUnknown options The Single-IP Mode toggle in Newznab's Zyclops health proxy subsection has default: true. The boolean renderer falls back to the schema default at display time (template-option.tsx:335), so the toggle correctly reads ON when localValue is undefined. But the subsection modal seeds localValue from the saved object only — sub-option defaults are never merged in — so a user who never explicitly toggles the field saves zyclopsHealthProxy without singleIp, and downstream the addon coerces undefined → '0'. Result for affected users: outbound proxy requests include single_ip=0 while the UI shows Single-IP Mode enabled. For an indexer-fronting proxy where each request hits the upstream indexer from the user's own IP, this is the difference between TOS-compliant and ban-risking traffic. Fix is in two parts: 1. Newznab preset (generateAddons): apply the schema defaults (singleIp ?? true, showUnknown ?? false) so existing user configs missing the field — saved before this fix, or saved without toggling — are corrected on next manifest generation. No user resave required. This pattern is already used in other presets (meteor.ts, flixStreams.ts). 2. TemplateOption subsection: seed the modal's localValue with sub-option defaults merged under the saved value. This prevents the same class of bug recurring for any future subsection that defines a `default: true` (or any non-undefined default) field. Saved values still win — only undefined sub-options pick up defaults.
1 parent 1c142de commit 9d0a2fb

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎packages/core/src/presets/newznab.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ export class NewznabPreset extends BuiltinAddonPreset {
405405
enabled: true,
406406
backbones: options.zyclopsHealthProxy.backbones,
407407
providerHosts: providerHosts,
408-
showUnknown: options.zyclopsHealthProxy.showUnknown,
409-
singleIp: options.zyclopsHealthProxy.singleIp,
408+
showUnknown: options.zyclopsHealthProxy.showUnknown ?? false,
409+
singleIp: options.zyclopsHealthProxy.singleIp ?? true,
410410
};
411411
}
412412
const config: Record<string, any> = {

‎packages/frontend/src/components/shared/template-option.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,17 @@ const TemplateOption: React.FC<TemplateOptionProps> = ({
566566
case 'subsection': {
567567
const [modalOpen, setModalOpen] = useState(false);
568568
const subOptions = (option.subOptions ?? []) as Option[];
569-
const currentValue = (forcedValue ??
569+
const savedValue = (forcedValue ??
570570
value ??
571571
defaultValue ??
572572
{}) as Record<string, any>;
573+
const subDefaults: Record<string, any> = {};
574+
for (const sub of subOptions) {
575+
if (sub.default !== undefined) {
576+
subDefaults[sub.id] = sub.default;
577+
}
578+
}
579+
const currentValue = { ...subDefaults, ...savedValue };
573580

574581
const [localValue, setLocalValue] =
575582
useState<Record<string, any>>(currentValue);

0 commit comments

Comments
 (0)