mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6044] [CLOSED] feat(clients): multiply recorded traffic by per-client ratio #6059
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#6059
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/6044
Author: @HamidRezaSZ
Created: 7/19/2026
Status: ❌ Closed
Base:
main← Head:feat/client-traffic-ratio📝 Commits (5)
2d2d2e3feat(clients): multiply recorded traffic by per-client ratioe2112e1fix(clients): normalize trafficRatio across create, update, and API reads82d2049docs(clients): document trafficRatio in wiki, README, and OpenAPIe5911a4fix(docs): align hosts API pages with groupId OpenAPI paths057334dfix(clients): address Copilot review on trafficRatio helpers📊 Changes
42 files changed (+1536 additions, -441 deletions)
View changed files
📝
README.md(+1 -1)📝
docs/architecture.md(+4 -2)📝
docs/content/docs/en/config/clients.mdx(+4 -1)📝
docs/content/docs/en/reference/api/hosts.mdx(+1 -1)📝
docs/content/docs/fa/config/clients.mdx(+4 -1)📝
docs/content/docs/fa/reference/api/hosts.mdx(+1 -1)📝
docs/content/docs/ru/config/clients.mdx(+4 -1)📝
docs/content/docs/ru/reference/api/hosts.mdx(+1 -1)📝
docs/content/docs/zh/config/clients.mdx(+2 -1)📝
docs/content/docs/zh/reference/api/hosts.mdx(+1 -1)📝
docs/lib/site-i18n.ts(+1 -1)📝
docs/public/openapi.json(+1141 -345)📝
frontend/public/mockServiceWorker.js(+21 -9)📝
frontend/public/openapi.json(+11 -1)📝
frontend/src/generated/examples.ts(+2 -0)📝
frontend/src/generated/schemas.ts(+11 -1)📝
frontend/src/generated/types.ts(+2 -0)📝
frontend/src/generated/zod.ts(+2 -0)📝
frontend/src/pages/clients/ClientBulkAddModal.tsx(+11 -0)📝
frontend/src/pages/clients/ClientFormModal.tsx(+16 -2)...and 22 more files
📄 Description
Summary
Add a per-client
trafficRatio(default1) that multiplies real traffic deltas before they are stored, so ratio2turns 10MB of real use into 20MB in the DB and panel while quota enforcement stays consistent. Unset or non-positive ratios are normalized to1on write and API read so the field never persists or returns as0.Why
Operators often want billed usage to differ from raw network usage (e.g. sell 1:2 traffic). Without a multiplier, the panel can only show real bytes. This lets each client set a ratio so recorded up/down (and remaining quota) reflect billed usage without changing how Xray reports stats.
Type of change
Areas affected
How was this tested?
2, save.client_trafficsup/down and the clients table show ~2× the real usage; quota depletes against the inflated counters.SetRemoteTrafficare scaled the same way; node baselines stay raw.trafficRatioand confirm GET returns1(not0); omit the field on update and confirm an existing custom ratio is preserved.TestAddClientTraffic_AppliesTrafficRatio,TestScaleTrafficBytes(internal/web/service)TestNormalizeClientTrafficRatio,TestClientToRecordNormalizesTrafficRatio,TestMergeClientRecordTrafficRatioResetToOne(internal/database/model)Screenshots / recordings
Breaking changes
None. Existing clients get
traffic_ratio = 1via AutoMigrate default (usage unchanged). Ratio only affects future deltas; historical counters are not rewritten. Inbound aggregate counters stay raw. Legacy rows that somehow stored0are normalized to1on API read and on the next write throughToRecord/ create-update defaults.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.