mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6240] [MERGED] feat(clients): give each client its own traffic reset cycle #6195
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#6195
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/6240
Author: @n0ctal
Created: 8/17/2026
Status: ✅ Merged
Merged: 8/18/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-per-client-traffic-reset📝 Commits (4)
256406ffeat(clients): give each client its own traffic reset cycle001adf4fix(clients): make the per-client reset cycle editable and safe to run3078d1eMerge branch 'main' into upstream-per-client-traffic-resetabaaec6fix(clients): validate renew fields on the bulk and import paths too📊 Changes
20 files changed (+761 additions, -74 deletions)
View changed files
📝
frontend/public/openapi.json(+24 -0)📝
frontend/src/generated/examples.ts(+4 -0)📝
frontend/src/generated/schemas.ts(+24 -0)📝
frontend/src/generated/types.ts(+4 -0)📝
frontend/src/generated/zod.ts(+4 -0)📝
frontend/src/pages/clients/ClientBulkAddModal.tsx(+25 -1)📝
frontend/src/pages/clients/ClientFormModal.tsx(+35 -1)📝
frontend/src/pages/inbounds/form/InboundFormModal.tsx(+1 -2)📝
frontend/src/schemas/client.ts(+6 -0)📝
frontend/src/schemas/primitives/index.ts(+1 -0)➕
frontend/src/schemas/primitives/traffic-reset.ts(+7 -0)📝
internal/database/db.go(+19 -0)📝
internal/database/model/model.go(+90 -69)➕
internal/web/job/periodic_traffic_reset_client_test.go(+206 -0)📝
internal/web/job/periodic_traffic_reset_job.go(+61 -1)📝
internal/web/service/client_bulk.go(+12 -0)📝
internal/web/service/client_crud.go(+64 -0)📝
internal/web/service/client_link.go(+8 -0)📝
internal/web/service/client_portable.go(+12 -0)➕
internal/web/service/client_traffic_cycle_test.go(+154 -0)📄 Description
Closes #5497.
Summary
Traffic reset lives on the inbound, so every client sharing one resets together. The issue's case is an operator running a monthly 1000GB plan next to a weekly 200GB plan: today that means pressing Reset Traffic by hand, per client, on a schedule kept in someone's head.
Clients now carry their own cycle.
Shape
The client fields are the inbound fields:
trafficReset(never | hourly | daily | weekly | monthly) andtrafficResetDayfor the monthly case, same vocabulary, same clamping, same monthly due-day rule via the existingmonthlyResetDue.PeriodicTrafficResetJobalready runs once per period; it now makes a second pass over the clients whose own cycle matches that period, after the inbound pass.A client left at
neverbehaves exactly as before — only its inbound's schedule touches it. A client whose own cycle happens to match its inbound's is reset twice in the same tick, which is harmless because the reset is idempotent, and I preferred that to making one schedule quietly suppress the other.What I left out, and why
The issue also asks for cron expressions and a choice of post-reset quota. I did not implement either. Both are product decisions rather than mechanics, and neither has an inbound-level counterpart, so adding them only for clients would put two different scheduling languages in one panel. The weekly day-of-week choice is out for the same reason: inbound weekly resets fire on the
@weeklyboundary, and a client-only weekday would diverge from it. Happy to add any of them if you want them — I would rather ask than guess.Persistence
The fields are on
ClientRecord, not only in the inbound settings JSON. That is deliberate and load-bearing: the paths that rebuild a client from the record — an ordinary edit, an attach, a traffic reset — write back whatever the record holds, so a field that lives only in the JSON is silently zeroed by routine panel use and the operator finds out a billing cycle later.An unknown period is rejected rather than coerced to
never. A coerced value leaves a field that reads as configured while no job ever selects the client, which is the worst of the three options.Validation
Three job tests against a real DB: a weekly client inside a
neverinbound is reset by the weekly run while a monthly client is not; a client atneversurvives all four periods; a monthly client is reset on its own day and not on another's.Mutation-checked — removing the client pass fails with
weekly client not reset by the weekly run: up=500 down=700, and removing the monthly due-day filter fails with the not-due client reset.Persistence is covered by driving the actual edit path (hydrate the record, change a comment, save) and asserting the inbound JSON, the record and
client_traffics; dropping the field fromToClientfails withinbound settings hold ""/15 after an unrelated edit. Validation is table-driven over the accepted and rejected shapes.go build ./...,go vet,golangci-lint, the full Go suite, frontend typecheck, eslint and 1158 unit tests all green.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.