From f84fb25de11acb9c6b019a02249e789a6445537e Mon Sep 17 00:00:00 2001 From: Viren070 Date: Fri, 19 Sep 2025 19:21:26 +0100 Subject: [PATCH] feat: allow customising which stats are shown --- packages/core/src/db/schemas.ts | 11 +++- packages/core/src/main.ts | 51 ++++++++++--------- packages/core/src/transformers/stremio.ts | 4 +- packages/core/src/utils/config.ts | 10 ++++ .../src/components/menu/miscellaneous.tsx | 35 +++++++++++-- 5 files changed, 79 insertions(+), 32 deletions(-) diff --git a/packages/core/src/db/schemas.ts b/packages/core/src/db/schemas.ts index 42b2c984..d0c0b5f4 100644 --- a/packages/core/src/db/schemas.ts +++ b/packages/core/src/db/schemas.ts @@ -410,8 +410,15 @@ export const UserDataSchema = z.object({ size: SizeFilterOptions.optional(), hideErrors: z.boolean().optional(), hideErrorsForResources: z.array(ResourceSchema).optional(), - showStatistics: z.boolean().optional(), - statisticsPosition: z.enum(['top', 'bottom']).optional(), + // showStatistics: z.boolean().optional(), + // statisticsPosition: z.enum(['top', 'bottom']).optional(), + statistics: z + .object({ + enabled: z.boolean().optional(), + position: z.enum(['top', 'bottom']).optional(), + statsToShow: z.array(z.enum(['addon', 'filter'])).optional(), + }) + .optional(), tmdbAccessToken: z.string().optional(), tmdbApiKey: z.string().optional(), tvdbApiKey: z.string().optional(), diff --git a/packages/core/src/main.ts b/packages/core/src/main.ts index 3d4c6714..8f18b3e2 100644 --- a/packages/core/src/main.ts +++ b/packages/core/src/main.ts @@ -145,7 +145,7 @@ export class AIOStreams { }> > { logger.info(`Handling stream request`, { type, id }); - + const statistics: { title: string; description: string }[] = []; // get a list of all addons that support the stream resource with the given type and id. const supportedAddons = []; for (const [instanceId, addonResources] of Object.entries( @@ -174,11 +174,15 @@ export class AIOStreams { } ); - const { streams, errors, statistics } = await this.fetcher.fetch( - supportedAddons, - type, - id - ); + const { + streams, + errors, + statistics: addonStatistics, + } = await this.fetcher.fetch(supportedAddons, type, id); + + if (this.userData.statistics?.statsToShow?.includes('addon')) { + statistics.push(...addonStatistics); + } // append initialisation errors to the errors array errors.push( @@ -243,25 +247,26 @@ export class AIOStreams { return groups; } - if (filterDetails.length > 0) { - const removalGroups = splitByPin(filterDetails); - for (const group of removalGroups) { - statistics.push({ - title: '🔍 Removal Reasons', - description: group.join('\n').trim(), - }); + if (this.userData.statistics?.statsToShow?.includes('filter')) { + if (filterDetails.length > 0) { + const removalGroups = splitByPin(filterDetails); + for (const group of removalGroups) { + statistics.push({ + title: '🔍 Removal Reasons', + description: group.join('\n').trim(), + }); + } + } + if (includedDetails.length > 0) { + const includedGroups = splitByPin(includedDetails); + for (const group of includedGroups) { + statistics.push({ + title: '🔍 Included Reasons', + description: group.join('\n').trim(), + }); + } } } - if (includedDetails.length > 0) { - const includedGroups = splitByPin(includedDetails); - for (const group of includedGroups) { - statistics.push({ - title: '🔍 Included Reasons', - description: group.join('\n').trim(), - }); - } - } - // return the final list of streams, followed by the error streams. logger.info( `Returning ${finalStreams.length} streams and ${errors.length} errors and ${statistics.length} statistic` diff --git a/packages/core/src/transformers/stremio.ts b/packages/core/src/transformers/stremio.ts index cb8c3d5b..afb20ab4 100644 --- a/packages/core/src/transformers/stremio.ts +++ b/packages/core/src/transformers/stremio.ts @@ -243,8 +243,8 @@ export class StremioTransformer { ); } - if (this.userData.showStatistics) { - let position = this.userData.statisticsPosition || 'bottom'; + if (this.userData.statistics?.enabled) { + let position = this.userData.statistics?.position || 'bottom'; let statisticStreams = statistics.map((statistic) => ({ name: statistic.title, description: statistic.description, diff --git a/packages/core/src/utils/config.ts b/packages/core/src/utils/config.ts index 837887e0..fb2b61e5 100644 --- a/packages/core/src/utils/config.ts +++ b/packages/core/src/utils/config.ts @@ -523,6 +523,16 @@ export function applyMigrations(config: any): UserData { behaviour: 'parallel', }; } + + if (config.showStatistics || config.statisticsPosition) { + config.statistics = { + enabled: config.showStatistics ?? false, + position: config.statisticsPosition ?? 'bottom', + statsToShow: ['addon', 'filter'], + }; + delete config.showStatistics; + delete config.statisticsPosition; + } return config; } diff --git a/packages/frontend/src/components/menu/miscellaneous.tsx b/packages/frontend/src/components/menu/miscellaneous.tsx index 4fd46e80..1c79da3a 100644 --- a/packages/frontend/src/components/menu/miscellaneous.tsx +++ b/packages/frontend/src/components/menu/miscellaneous.tsx @@ -197,27 +197,52 @@ function Content() { { setUserData((prev) => ({ ...prev, - showStatistics: value, + statistics: { + ...prev.statistics, + enabled: value, + }, })); }} />