[Feature] Allow operator to disable stream types#593
[Feature] Allow operator to disable stream types#593funkypenguin wants to merge 2 commits intoViren070:mainfrom
Conversation
Signed-off-by: David Young <davidy@funkypenguin.co.nz>
Signed-off-by: David Young <davidy@funkypenguin.co.nz>
WalkthroughThis pull request introduces configurable stream type filtering by adding a new environment variable Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/core/src/transformers/stremio.ts (2)
289-289: Unrelated improvement: nullish coalescing for provideStreamData.This change adds
?? falseto ensureprovideStreamDatais always a boolean. While this is a good defensive programming practice, it appears unrelated to the disabled stream types feature.Consider:
- Documenting this change in the commit message
- Verifying if this should be a separate commit/PR
244-301: Consider edge case: all streams filtered.If all streams match
DISABLED_STREAM_TYPES, users will receive an empty response with no explanation (unless statistics are enabled). This could be confusing.Consider adding a helpful error stream when
filteredStreams.length === 0 && streams.length > 0, informing users that all available streams were filtered by operator policy.💡 Example implementation
const filteredStreams = disabledStreamTypes.size ? streams.filter((stream) => { if (disabledStreamTypes.has(stream.type)) { filteredOutCounts[stream.type] = (filteredOutCounts[stream.type] || 0) + 1; return false; } return true; }) : streams; + +// If all streams were filtered and statistics are disabled, show helpful message +if (filteredStreams.length === 0 && streams.length > 0 && !this.userData.statistics?.enabled) { + return { + streams: [ + StremioTransformer.createErrorStream({ + errorTitle: '🚫 All Streams Filtered', + errorDescription: `All ${streams.length} available streams were removed by operator policy (disabled types: ${Array.from(disabledStreamTypes).join(', ')})`, + }) + ] + }; +}
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.env.samplepackages/core/src/transformers/stremio.tspackages/core/src/utils/env.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/core/src/transformers/stremio.ts (2)
packages/core/src/db/schemas.ts (2)
AIOStream(905-960)AIOStream(962-962)packages/core/src/utils/logger.ts (1)
getTimeTakenSincePoint(152-159)
🔇 Additional comments (4)
packages/core/src/transformers/stremio.ts (4)
244-260: LGTM! Efficient filtering implementation.The filtering logic is well-structured:
- Uses a
Setfor O(1) lookup performance- Only filters when necessary (checking
disabledStreamTypes.size)- Correctly tracks counts per stream type
- Preserves original array when no filtering is needed
261-276: Statistics tracking implemented correctly.The implementation properly:
- Creates a copy of the statistics array before modification
- Only adds the disabled types statistic when appropriate
- Provides clear per-type breakdown
The user-facing message "Streams of these types were removed by the operator" effectively communicates the filtering action.
295-301: Logging update enhances observability.The filtered summary addition to the log message provides clear feedback about filtering actions, including correct pluralisation for singular/plural streams.
317-317: Correct use of augmented statistics list.Properly uses
statisticsListto include the disabled stream types statistic when applicable.
| DISABLED_STREAM_TYPES: str({ | ||
| default: undefined, | ||
| desc: 'Comma separated list of stream types that should never be returned to clients (e.g., p2p,http,live).', | ||
| }), |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# First, examine the env.ts file around the DISABLED_STREAM_TYPES definition
echo "=== Examining env.ts around DISABLED_STREAM_TYPES ==="
sed -n '350,380p' packages/core/src/utils/env.tsRepository: Viren070/AIOStreams
Length of output: 1365
🏁 Script executed:
#!/bin/bash
# Search for StreamTypes definition or constants
echo "=== Searching for StreamTypes definition ==="
rg -nP 'StreamTypes|stream.*type' --type=ts -i | head -30Repository: Viren070/AIOStreams
Length of output: 3109
🏁 Script executed:
#!/bin/bash
# Search for how DISABLED_STREAM_TYPES is used in the codebase
echo "=== Searching for DISABLED_STREAM_TYPES usage ==="
rg -nP 'DISABLED_STREAM_TYPES' --type=ts -B2 -A2Repository: Viren070/AIOStreams
Length of output: 933
🏁 Script executed:
#!/bin/bash
# Find the STREAM_TYPES constant definition
echo "=== STREAM_TYPES definition ==="
sed -n '50,80p' packages/frontend/src/components/menu/filters.tsxRepository: Viren070/AIOStreams
Length of output: 981
🏁 Script executed:
#!/bin/bash
# See how disabledStreamTypes is used after parsing
echo "=== disabledStreamTypes usage context ==="
sed -n '240,270p' packages/core/src/transformers/stremio.tsRepository: Viren070/AIOStreams
Length of output: 1154
🏁 Script executed:
#!/bin/bash
# Search for actual stream type values in the codebase
echo "=== Stream type values used ==="
rg -nP "type.*:.*['\"](?:p2p|http|live|debrid|usenet|statistic|error)" --type=ts | head -20Repository: Viren070/AIOStreams
Length of output: 1804
🏁 Script executed:
#!/bin/bash
# Find the STREAM_TYPES constant in constants file
echo "=== STREAM_TYPES constant definition ==="
rg -nP 'export.*STREAM_TYPES' packages/core/src/utils/constants.ts -A10Repository: Viren070/AIOStreams
Length of output: 587
🏁 Script executed:
#!/bin/bash
# Check all files in constants to find STREAM_TYPES
echo "=== Looking for STREAM_TYPES in constants ==="
cat packages/core/src/utils/constants.ts | grep -A20 "STREAM_TYPES"Repository: Viren070/AIOStreams
Length of output: 1416
🏁 Script executed:
#!/bin/bash
# Search for stream type definitions or enums
echo "=== Searching for stream type enum or type definition ==="
rg -nP "type.*Stream.*Type|enum.*Stream" --type=ts -B2 -A5 | head -50Repository: Viren070/AIOStreams
Length of output: 3733
🏁 Script executed:
#!/bin/bash
# Find the actual values of the stream type constants
echo "=== Stream type constant values ==="
grep -nP "(P2P|LIVE|USENET|ARCHIVE|DEBRID|HTTP|EXTERNAL|YOUTUBE|ERROR|STATISTIC)_STREAM_TYPE\s*=" packages/core/src/utils/constants.ts | head -20Repository: Viren070/AIOStreams
Length of output: 750
Add validation and normalisation for stream types.
The configuration currently accepts any string without validating against known stream types (p2p, live, stremio-usenet, archive, usenet, debrid, http, external, youtube, error, statistic). Additionally, there is no case normalisation during parsing, making the matching case-sensitive. This could lead to silent failures if operators mistype stream types or use incorrect casing.
Consider:
- Validating parsed values against the
STREAM_TYPESconstant to reject invalid entries - Normalising to lowercase during parsing (or during comparison) to prevent case-sensitivity issues
🤖 Prompt for AI Agents
In packages/core/src/utils/env.ts around lines 364-367, the
DISABLED_STREAM_TYPES config currently accepts any string and is case-sensitive;
update it to parse the comma-separated value into trimmed, lowercased tokens,
remove empties, validate each token against the STREAM_TYPES constant, and
reject (throw/raise a config validation error) if any unknown types are present;
normalize the stored value (or comparison path) to the validated lowercased
array so downstream checks are case-insensitive.
We've implemented this on the ElfHosted instance as of 1 Jan 2026, allowing us to apply our new policy of disabling non-debrid streams (P2P, live, HTTP) on our public instances. I've tried to make it as consistent as possible with the existing
DISABLED_options, and it adds a statistics entry if streams were disabled due to operator policy, like this:Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.