mirror of
https://github.com/Viren070/AIOStreams.git
synced 2025-12-01 23:14:04 +01:00
feat: allow customising which stats are shown
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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,6 +247,7 @@ export class AIOStreams {
|
||||
return groups;
|
||||
}
|
||||
|
||||
if (this.userData.statistics?.statsToShow?.includes('filter')) {
|
||||
if (filterDetails.length > 0) {
|
||||
const removalGroups = splitByPin(filterDetails);
|
||||
for (const group of removalGroups) {
|
||||
@@ -261,7 +266,7 @@ export class AIOStreams {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 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`
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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')[],
|
||||
},
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user