feat(sub): auto-detect subscription format by User-Agent (Updated)#5826
feat(sub): auto-detect subscription format by User-Agent (Updated)#5826Tomilla wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
Reviewed the diff and traced the new auto-detect path end to end (internal/sub/controller.go, internal/sub/sub.go, internal/web/service/setting.go, internal/web/controller/setting.go), and cross-checked the generated OpenAPI/frontend artifacts plus all 13 translation files.
This is a well-engineered, backward-compatible change: auto-detection defaults to off and is gated behind both the auto-detect flag and the underlying format being enabled, the NewSUBController functional-options refactor threads every option through correctly at its only call site (internal/sub/sub.go), the new User-Agent regexes are validated both client-side (GoRegexInput) and server-side (validateSubUserAgentRegexes in internal/web/service/setting.go) with a sensible empty-inherits-default contract, and all 13 locale JSON files received the new keys (verified they parse and contain the expected key set). No correctness, security, or backward-compatibility problems were found.
Two non-blocking suggestions, both inline below:
-
A cosmetic indentation regression in endpoints.ts on the two pre-existing entries this PR edited.
-
The Balancer cost-regex validation UX in BalancerFormModal.tsx is unrelated to subscription format auto-detection; consider splitting it into its own PR.
This review was generated automatically by an AI agent; a maintainer may still want to follow up. An earlier placeholder comment posted on this PR during tooling verification can be disregarded.
|
The CI failure was caused by the following network error, and it is not a problem with the PR code.
|
…ntRegex - Use NewErrorf with proper formatting instead of NewError with string concatenation - Add comment explaining the rationale for returning original pattern value - This preserves the intentional design where empty input is stored as empty in the DB and inherited as the runtime default at read time
|
All suggestions have been addressed. The PR is ready for review. |
… apps Repo policy forbids third-party client app names in source and locale strings. Removes Streisand/Stash/v2rayN(G/A) from Go defaults, TSX placeholders, entity descriptions, and all 13 locales; keeps allowed format names Clash/Mihomo. Trims added Go comments. Merges current main and regenerates OpenAPI/schemas.
I fully agree with this approach in the interest of maintaining platform neutrality. When configurable regular expressions were originally added, the intent was precisely to give users the flexibility to make adjustments based on their actual User-Agents. Since some clients (like V2rayA and V2rayNG) cannot adjust their User-Agents autonomously, while others (like Clash Verge and Premium) support custom User-Agents, relying on user-configured regex rather than hardcoded client names makes perfect sense. @MHSanaei I fully support these adjustments. Are there any other review comments or further changes needed before we move forward? |
Summary
Adds optional User-Agent detection to serve Clash/Mihomo YAML or Xray JSON from the standard subscription URL.
The panel now exposes JSON and Clash/Mihomo endpoint paths, reverse proxy URLs, auto-detection controls, and configurable Go RE2 User-Agent patterns.
Why
Raw, JSON, and Clash subscriptions currently use separate URLs. This is inconvenient for administrators and users migrating from panels that use one subscription URL and select the response format based on the requesting client.
This change retains every existing endpoint while optionally allowing the standard subscription URL to return the appropriate format.
Auto-detection is disabled by default, preserving existing behavior.
Closes #5570
This PR also fixes a bug: when a user has enabled JSON subscription but has no place to modify the JSON subscription path, a prompt "Default JSON subscription path "/json/" is well-known - change it." is constantly displayed upon saving.
Type of change
Areas affected
How was this tested?
Automated checks:
go build ./...go test ./...npm run typechecknpm run lintnpm run test -- --run— 704 tests passednpm run buildManual subscription checks:
Screenshots / recordings
Subscription settings link
JSON and Clash/Mihomo format settings
User-Agent auto-detection
Go RE2 validation
User-Agent regex:
Breaking changes
None.
Existing subscription URLs and response behavior remain unchanged unless an administrator explicitly enables auto-detection. Existing JSON and Clash/Mihomo endpoints remain available.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.