mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6046] [CLOSED] feat(inbounds): multiply client usage by inbound trafficRatio #6060
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#6060
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6046
Author: @HamidRezaSZ
Created: 7/19/2026
Status: ❌ Closed
Base:
main← Head:feat/inbound-traffic-ratio📝 Commits (4)
f71be2dfeat(inbounds): multiply client usage by inbound trafficRatio1fccce5test(frontend): refresh inbound-full snapshots for trafficRatio66da63efix(inbounds): persist and normalize trafficRatio on updatee451abffix(inbounds): persist and normalize trafficRatio on update📊 Changes
41 files changed (+1534 additions, -364 deletions)
View changed files
📝
README.md(+1 -0)📝
docs/architecture.md(+8 -2)📝
docs/content/docs/en/config/clients.mdx(+4 -1)📝
docs/content/docs/en/config/inbounds.mdx(+7 -0)📝
docs/content/docs/en/reference/api/hosts.mdx(+1 -1)📝
docs/content/docs/fa/reference/api/hosts.mdx(+1 -1)📝
docs/content/docs/ru/reference/api/hosts.mdx(+1 -1)📝
docs/content/docs/zh/reference/api/hosts.mdx(+1 -1)📝
docs/public/openapi.json(+1136 -344)📝
frontend/public/openapi.json(+8 -0)📝
frontend/src/generated/examples.ts(+1 -0)📝
frontend/src/generated/schemas.ts(+7 -0)📝
frontend/src/generated/types.ts(+1 -0)📝
frontend/src/generated/zod.ts(+1 -0)📝
frontend/src/lib/xray/inbound-form-adapter.ts(+4 -0)📝
frontend/src/models/dbinbound.ts(+3 -0)📝
frontend/src/pages/inbounds/form/InboundFormModal.tsx(+10 -0)📝
frontend/src/schemas/api/inbound.ts(+1 -0)📝
frontend/src/schemas/forms/inbound-form.ts(+1 -0)📝
frontend/src/test/__snapshots__/inbound-full.test.ts.snap(+8 -0)...and 21 more files
📄 Description
Summary
Add a per-inbound
trafficRatio(default1) that scales attached clients' recorded traffic deltas so billed usage and quota use the multiplier, while inbound aggregate counters stay raw. Create and update paths both persist and normalize the field (≤0/ invalid →1), with a DB backfill for existing rows.Multi-attach note: Xray reports client traffic per email only. A client on several inbounds with different ratios is billed at the ratio of the attached inbound with the lowest
id(local polls). Prefer matching ratios across shared inbounds, or a single attachment, when billing must be exact. Node sync applies the reporting inbound’s ratio once per email delta.Why
Operators often need to bill or quota clients at a different rate than actual bytes transferred (e.g. ratio
2so 10 MB real becomes 20 MB recorded). Putting the multiplier on the inbound keeps one setting for all clients on that inbound and avoids per-client configuration drift.Type of change
Areas affected
How was this tested?
2, then edit it to another value and confirm the change is persisted (not stuck at create-time).1on add, update, and after migration backfill.TestAddClientTraffic_AppliesTrafficRatio,TestScaleTrafficBytes,TestNormalizeTrafficRatio,TestUpdateInbound_PersistsTrafficRatio,TestUpdateInbound_TrafficRatioClampedToOne,TestAddInbound_TrafficRatioClampedToOne.Screenshots / recordings
Breaking changes
None. Existing inbounds get
trafficRatio = 1via the DB default andnormalizeInboundTrafficRatiobackfill, so recorded usage is unchanged until an operator sets a different ratio.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.