From 7b776405e17cce39313cbdcf7253db504286ad2b Mon Sep 17 00:00:00 2001 From: Viren070 Date: Wed, 26 Nov 2025 22:53:15 +0000 Subject: [PATCH] fix(builtins/nab): handle no title and empty channel --- packages/core/src/builtins/base/nab/api.ts | 68 +++++++++++++++------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/packages/core/src/builtins/base/nab/api.ts b/packages/core/src/builtins/base/nab/api.ts index dd25a7c7..a241a5c3 100644 --- a/packages/core/src/builtins/base/nab/api.ts +++ b/packages/core/src/builtins/base/nab/api.ts @@ -55,7 +55,9 @@ const NabCapsSearchingSchema = z const CapabilitiesSchema = z .object({ caps: z.object({ - server: z.array(z.object({ $: z.object({ title: z.string() }) })), + server: z.array( + z.object({ $: z.object({ title: z.string().optional() }) }) + ), limits: z .array( z.object({ @@ -243,25 +245,37 @@ export class BaseNabApi { .object({ rss: z.object({ channel: z.array( - z.object({ - item: z.array(createTorznabItemSchema()).optional().default([]), - 'torznab:response': z.array(ResponseAttributeSchema).optional(), - 'newznab:response': z.array(ResponseAttributeSchema).optional(), - response: z.array(ResponseAttributeSchema).optional(), - }) + z.union([ + z.literal(''), + z.object({ + item: z + .array(createTorznabItemSchema()) + .optional() + .default([]), + 'torznab:response': z + .array(ResponseAttributeSchema) + .optional(), + 'newznab:response': z + .array(ResponseAttributeSchema) + .optional(), + response: z.array(ResponseAttributeSchema).optional(), + }), + ]) ), }), }) .transform((data) => { const channel = data.rss.channel[0]; const response = - channel['torznab:response']?.[0] ?? - channel['newznab:response']?.[0] ?? - channel.response?.[0]; + channel === '' + ? undefined + : (channel['torznab:response']?.[0] ?? + channel['newznab:response']?.[0] ?? + channel.response?.[0]); return { offset: response?.offset, total: response?.total, - results: channel.item, + results: channel === '' ? [] : channel.item, }; }); } else { @@ -269,25 +283,37 @@ export class BaseNabApi { .object({ rss: z.object({ channel: z.array( - z.object({ - item: z.array(createNewznabItemSchema()).optional().default([]), - 'newznab:response': z.array(ResponseAttributeSchema).optional(), - 'torznab:response': z.array(ResponseAttributeSchema).optional(), - response: z.array(ResponseAttributeSchema).optional(), - }) + z.union([ + z.literal(''), + z.object({ + item: z + .array(createNewznabItemSchema()) + .optional() + .default([]), + 'torznab:response': z + .array(ResponseAttributeSchema) + .optional(), + 'newznab:response': z + .array(ResponseAttributeSchema) + .optional(), + response: z.array(ResponseAttributeSchema).optional(), + }), + ]) ), }), }) .transform((data) => { const channel = data.rss.channel[0]; const response = - channel['newznab:response']?.[0] ?? - channel['torznab:response']?.[0] ?? - channel.response?.[0]; + channel === '' + ? undefined + : (channel['torznab:response']?.[0] ?? + channel['newznab:response']?.[0] ?? + channel.response?.[0]); return { offset: response?.offset, total: response?.total, - results: channel.item, + results: channel === '' ? [] : channel.item, }; }); }