mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5332] [Feature]: Allow to use negative sorting order (index) in inbounds #3736
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3736
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Ponywka on GitHub (Jun 14, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5332
Is your feature request related to a problem?
I have servers that stand out for their stability and speed. I’d like to set them as the primary inbound in the subscription. Currently, to do this, I have to assign a higher index to each slower inbounds. I’d prefer to simply assign a negative index to the primary inbound server once, and leave the rest at their default values.
Describe the solution you'd like
I already did it in https://github.com/MHSanaei/3x-ui/pull/5214.
Allow to users sets a negative sorting index
Alternatives you've considered
No response
Concrete use case
No response
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
No response
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Jun 14, 2026):
The
subSortIndexfield you described from PR #5214 was already landed in a rescoped form — it controls subscription output order (ORDER BY sub_sort_index ASC, id ASCininternal/sub/service.go:304). The field is present in the inbound form and in the panel's column list. However, the current implementation enforces a minimum of 1 at every layer, which prevents the use case you describe.Where the constraint is enforced
internal/database/model/model.go:53— GORM model tagvalidate:"omitempty,gte=1"; column default1internal/web/service/inbound_util.go:13-18—normalizeSubSortIndex()clamps any value< 1to1on both the add and update pathsinternal/database/db.go:133-134—normalizeInboundSubSortIndex()runs at startup and executesUPDATE inbounds SET sub_sort_index = 1 WHERE sub_sort_index < 1, so any row written with a negative value would be lifted to1on the next restartfrontend/src/schemas/forms/inbound-form.ts:42—z.number().int().min(1).default(1)frontend/src/lib/xray/inbound-form-adapter.ts:193—Math.max(1, row.subSortIndex ?? 1)on readfrontend/src/generated/zod.ts:317— generated API schema also enforcesmin(1)Why the minimum was set to 1
The comment in
inbound_util.goexplains: an omittedsubSortIndexkey in the request body binds to Go's zero value (0), and the intent was that unset fields must not sort ahead of inbounds that have been explicitly ranked. The1-floor serves as both the default and the sentinel for "no explicit rank."What allowing negatives would require
To support negative values, all six enforcement points above would need to change consistently:
validatetag floor (e.g.gte=-32768) and adjust the GORM column default if a non-zero default is desired for backward compatibility.normalizeSubSortIndexto treat only the true zero-from-missing-field case specially (e.g. map0→ a positive default, allow all other values through), or remove the clamping entirely if0is no longer a sentinel.normalizeInboundSubSortIndexso existing rows are not lifted.inbound-form.ts, re-runnpm run genforgenerated/zod.ts) and the form adapter'sMath.maxcall.The backend service tests in
internal/web/service/inbound_sub_sort_test.goexplicitly assert that-3and0are clamped to1; those would need to be updated to match the new contract.If you want to contribute this change, a PR that adjusts the minimum consistently across all six sites and updates the tests would be the right approach. The maintainer confirmed in the PR #5214 comment that the underlying use case is considered valid.
This reply was generated automatically; a maintainer may follow up.