feat: allow customising which stats are shown

This commit is contained in:
Viren070
2025-09-19 19:21:26 +01:00
parent edbcc272e7
commit f84fb25de1
5 changed files with 79 additions and 32 deletions
+9 -2
View File
@@ -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(),
+28 -23
View File
@@ -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`
+2 -2
View File
@@ -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,
+10
View File
@@ -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;
}
@@ -197,27 +197,52 @@ function Content() {
<Switch
label="Enable"
side="right"
value={userData.showStatistics}
value={userData.statistics?.enabled}
onValueChange={(value) => {
setUserData((prev) => ({
...prev,
showStatistics: value,
statistics: {
...prev.statistics,
enabled: value,
},
}));
}}
/>
<Select
label="Statistics Position"
help="Whether to show the statistic streams at the top or bottom of the stream list."
disabled={!userData.showStatistics}
disabled={!userData.statistics?.enabled}
options={[
{ label: 'Top', value: 'top' },
{ label: 'Bottom', value: 'bottom' },
]}
value={userData.statisticsPosition || 'bottom'}
value={userData.statistics?.position || 'bottom'}
onValueChange={(value) => {
setUserData((prev) => ({
...prev,
statisticsPosition: value as 'top' | 'bottom',
statistics: {
...prev.statistics,
position: value as 'top' | 'bottom',
},
}));
}}
/>
<Combobox
label="Statistics to Show"
options={['addon', 'filter'].map((statistic) => ({
label: statistic,
value: statistic,
}))}
emptyMessage="No statistics to show"
multiple
value={userData.statistics?.statsToShow}
onValueChange={(value) => {
setUserData((prev) => ({
...prev,
statistics: {
...prev.statistics,
statsToShow: value as ('addon' | 'filter')[],
},
}));
}}
/>