Add clean filename stream redirect#950
Conversation
WalkthroughThis PR introduces a clean filename redirect feature that allows stream URLs to be rewritten to pass sanitised filenames whilst redirecting to the original stream, useful for subtitle matching in clients like Infuse. The change spans schema definitions, core redirect utilities, a new API endpoint, server integration, frontend settings, and user documentation. ChangesClean Filename Redirect Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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.
🧹 Nitpick comments (2)
packages/server/src/utils/cleanRedirect.ts (2)
56-58: 💤 Low valueConsider broadening the video extension whitelist.
The current regex only permits
mkv|mp4|avi|mov|m4v|webm, which will force.mkvon streams with legitimate formats like.ts(MPEG-TS),.flv,.wmv, or.mpg. Whilst this won't break playback, it may mislead clients that rely on extension-based format detection.📝 Suggested extension additions
- if (!/\.(mkv|mp4|avi|mov|m4v|webm)$/i.test(name)) { + if (!/\.(mkv|mp4|avi|mov|m4v|webm|ts|flv|wmv|mpg|mpeg|ogv|3gp)$/i.test(name)) { name += '.mkv'; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/server/src/utils/cleanRedirect.ts` around lines 56 - 58, The video-extension whitelist in cleanRedirect.ts currently only allows mkv|mp4|avi|mov|m4v|webm and forces ".mkv" otherwise; update the regex used where the variable name is checked (the /\. (mkv|mp4|avi|mov|m4v|webm)$/i test) to include other common container extensions such as ts|flv|wmv|mpg|mpeg|3gp (or broaden to a more comprehensive list of video extensions) so legitimate stream filenames keep their correct extension instead of being coerced to .mkv; make sure the updated regex remains case-insensitive and still appends '.mkv' only when no known video extension matches.
118-122: 💤 Low valueFallback filename uses 1-based indexing.
Because
originalStreamIndex++post-increments during the ternary evaluation at line 112, the fallback at line 121 produces 1-based numbering (e.g.,stream-1.mkvfor the first non-internal stream). Whilst this doesn't affect functionality, it's slightly inconsistent with typical 0-based conventions.🔢 Proposed adjustment for 0-based fallback
const filename = sanitizeFilename( parsed?.filename || stream.behaviorHints?.filename || - `stream-${originalStreamIndex}.mkv` + `stream-${originalStreamIndex - 1}.mkv` );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/server/src/utils/cleanRedirect.ts` around lines 118 - 122, The fallback filename uses a post-incremented originalStreamIndex causing 1-based numbering; update the fallback so it uses the pre-increment 0-based index (e.g., use originalStreamIndex instead of originalStreamIndex++ or compute an explicit indexBefore = originalStreamIndex and use that) when forming the `stream-${...}.mkv` fallback in the `sanitizeFilename` expression (references: sanitizeFilename, parsed?.filename, stream.behaviorHints?.filename, originalStreamIndex). Ensure any increment still happens where intended but not inside the ternary that builds the fallback.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/server/src/utils/cleanRedirect.ts`:
- Around line 56-58: The video-extension whitelist in cleanRedirect.ts currently
only allows mkv|mp4|avi|mov|m4v|webm and forces ".mkv" otherwise; update the
regex used where the variable name is checked (the /\.
(mkv|mp4|avi|mov|m4v|webm)$/i test) to include other common container extensions
such as ts|flv|wmv|mpg|mpeg|3gp (or broaden to a more comprehensive list of
video extensions) so legitimate stream filenames keep their correct extension
instead of being coerced to .mkv; make sure the updated regex remains
case-insensitive and still appends '.mkv' only when no known video extension
matches.
- Around line 118-122: The fallback filename uses a post-incremented
originalStreamIndex causing 1-based numbering; update the fallback so it uses
the pre-increment 0-based index (e.g., use originalStreamIndex instead of
originalStreamIndex++ or compute an explicit indexBefore = originalStreamIndex
and use that) when forming the `stream-${...}.mkv` fallback in the
`sanitizeFilename` expression (references: sanitizeFilename, parsed?.filename,
stream.behaviorHints?.filename, originalStreamIndex). Ensure any increment still
happens where intended but not inside the ternary that builds the fallback.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fb128acc-aca7-46ac-b0d2-10a6c6e869c1
📒 Files selected for processing (12)
packages/core/src/db/schemas.tspackages/core/src/utils/config.tspackages/core/src/utils/fieldMeta.tspackages/docs/content/docs/guides/clean-filename-redirect.mdxpackages/docs/content/docs/guides/meta.jsonpackages/frontend/src/components/menu/miscellaneous/_components/playback-behavior.tsxpackages/frontend/src/context/userData.tsxpackages/server/src/app.tspackages/server/src/routes/api/index.tspackages/server/src/routes/api/streamGate.tspackages/server/src/routes/stremio/stream.tspackages/server/src/utils/cleanRedirect.ts
Summary
Adds an optional Clean Filename Redirect output mode for streams.
When enabled, HTTP stream URLs are rewritten through:
/api/v1/stream-gate/:data/:filename
The gate responds with a redirect to the original stream URL while exposing a clean filename in the initial URL path and Content-Disposition header.
Behavior
Testing
Note: frontend lint was not run as a valid check because
next lintopens the ESLint setup wizard in this package.Summary by CodeRabbit
Release Notes
New Features
Documentation