Skip to content

Add clean filename stream redirect#950

Open
peralta00 wants to merge 1 commit into
Viren070:mainfrom
peralta00:feat/clean-filename-redirect
Open

Add clean filename stream redirect#950
peralta00 wants to merge 1 commit into
Viren070:mainfrom
peralta00:feat/clean-filename-redirect

Conversation

@peralta00

@peralta00 peralta00 commented May 13, 2026

Copy link
Copy Markdown

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

  • Disabled by default
  • Preserves existing formatter output
  • Does not proxy video traffic
  • Only wraps HTTP/HTTPS stream URLs
  • Default redirect code: 307

Testing

  • pnpm build
  • pnpm -F core test
  • pnpm -F server test
  • pnpm -F frontend test
  • pnpm -F docs build
  • Tested locally with Fusion + Infuse 8.4
  • Confirmed Infuse requests the clean filename URL and receives 307 redirect

Note: frontend lint was not run as a valid check because next lint opens the ESLint setup wizard in this package.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Clean Filename Redirect setting in Playback behaviour options. Toggle to enable/disable, with configurable HTTP redirect codes (302, 307, or 308). Disabled by default.
  • Documentation

    • Added guide for Clean Filename Redirect feature.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This 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.

Changes

Clean Filename Redirect Feature

Layer / File(s) Summary
Schema & Type Contracts
packages/core/src/db/schemas.ts
Introduces CleanRedirectOutputConfig type with optional enabled flag and redirectCode union (302/307/308); adds cleanRedirectOutput field to UserDataSchema with default {enabled: false, redirectCode: 307}; updates merge strategy configuration.
Redirect Gate Core Utilities
packages/server/src/utils/cleanRedirect.ts
Implements safe redirect processing: repeated URL decoding with bounded iterations, filename sanitisation with video extension enforcement, HTTP(S) URL validation, base URL computation, and main wrapStreamsWithCleanRedirectGate logic that conditionally rewrites eligible stream URLs based on user settings.
Stream Gate API Endpoint
packages/server/src/routes/api/streamGate.ts
Express router handling GET /:data/:filename that decrypts encrypted payload, parses JSON into CleanRedirectPayload, validates URL and redirect code (302/307/308), sanitises filename, sets response headers, and issues HTTP redirect; returns 400 for invalid decryption, JSON, URL, or code.
Server Routing & Stream Integration
packages/server/src/app.ts, packages/server/src/routes/api/index.ts, packages/server/src/routes/stremio/stream.ts
Registers streamGateApi router at /stream-gate in versioned API; integrates wrapStreamsWithCleanRedirectGate into stream response handler to post-process transformed streams and rewrite eligible URLs to stream-gate endpoints.
Frontend Settings UI
packages/frontend/src/context/userData.tsx, packages/frontend/src/components/menu/miscellaneous/_components/playback-behavior.tsx
Adds cleanRedirectOutput to DefaultUserData; introduces "Clean Filename Redirect" settings card with enable toggle and redirect code selector (defaulting to 307, disabled when feature is off).
Configuration & Metadata
packages/core/src/utils/config.ts, packages/core/src/utils/fieldMeta.ts
Registers cleanRedirectOutput in MISC_FIELDS for config merge-strategy inheritance; adds FIELD_META entry with label, group, type, menu, sub-tab, and redirect-related search keywords.
Documentation
packages/docs/content/docs/guides/clean-filename-redirect.mdx, packages/docs/content/docs/guides/meta.json
New guide explaining clean filename redirect feature, its use case (subtitle matching), HTTP 307 recommendation, disabled-by-default state, and that it does not proxy video traffic; updates guide index.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • Viren070

Poem

🐰 A filename flows through streams so clean,
Redirects with grace to URLs serene,
No proxying here, just paths made right,
With Infuse subtitles matching bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Add clean filename stream redirect' accurately summarises the main change: a new feature enabling optional HTTP stream URL rewriting with a clean filename redirect mechanism.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/server/src/utils/cleanRedirect.ts (2)

56-58: 💤 Low value

Consider broadening the video extension whitelist.

The current regex only permits mkv|mp4|avi|mov|m4v|webm, which will force .mkv on 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 value

Fallback 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.mkv for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 872351f and 3165e17.

📒 Files selected for processing (12)
  • packages/core/src/db/schemas.ts
  • packages/core/src/utils/config.ts
  • packages/core/src/utils/fieldMeta.ts
  • packages/docs/content/docs/guides/clean-filename-redirect.mdx
  • packages/docs/content/docs/guides/meta.json
  • packages/frontend/src/components/menu/miscellaneous/_components/playback-behavior.tsx
  • packages/frontend/src/context/userData.tsx
  • packages/server/src/app.ts
  • packages/server/src/routes/api/index.ts
  • packages/server/src/routes/api/streamGate.ts
  • packages/server/src/routes/stremio/stream.ts
  • packages/server/src/utils/cleanRedirect.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant