mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #7031] Show each client's lifetime traffic, change history and per-node usage from the client editor #6587
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#6587
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/7031
Author: @Zaltapar
Created: 10/30/2026
Status: 🔄 Open
Base:
main← Head:feat/client-usage-history📝 Commits (2)
628a949feat(clients): usage history and change log behind the edit modal's button3e69167fix(clients): close the review gaps in the usage-history archiving📊 Changes
43 files changed (+2923 additions, -32 deletions)
View changed files
📝
docs/content/docs/en/reference/api/clients.mdx(+31 -1)📝
docs/public/openapi.json(+258 -0)📝
frontend/public/openapi.json(+258 -0)➕
frontend/src/api/queries/useClientUsageHistoryQuery.ts(+30 -0)📝
frontend/src/api/queryKeys.ts(+1 -0)➕
frontend/src/components/clients/ClientUsageHistoryModal.tsx(+266 -0)📝
frontend/src/generated/examples.ts(+59 -0)📝
frontend/src/generated/schemas.ts(+176 -0)📝
frontend/src/generated/types.ts(+37 -0)📝
frontend/src/generated/zod.ts(+41 -0)➕
frontend/src/lib/clients/usage-history.ts(+80 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+15 -0)📝
frontend/src/pages/clients/ClientFormModal.tsx(+19 -0)➕
frontend/src/test/client-usage-history-modal.test.tsx(+113 -0)📝
internal/database/db.go(+2 -0)📝
internal/database/migrate_data.go(+2 -0)➕
internal/database/model/client_change_log.go(+13 -0)➕
internal/database/model/client_traffic_window.go(+12 -0)📝
internal/web/controller/client.go(+11 -0)📝
internal/web/service/client_bulk.go(+65 -2)...and 23 more files
📄 Description
Summary
A new button in the client edit section opens the client's full usage & change history:
Why
Renewing or resetting a client currently zeroed
client_traffics.up/downand the used amount was gone — a reseller could not answer "how much has this client ever used, on which node, and who changed its limits when". The panel already tracks per-node counters (node_client_traffics); the missing pieces were the archived closed windows and a metadata change log, surfaced somewhere the operator already looks (the client editor).Type of change
Areas affected
Changes
New tables (auto-migrated; empty on upgrade):
client_traffic_windows— one row per closed counter window:email, at, up, down, reason(reset | renew | deleted | renamed), indexed by email+time.client_change_logs— one row per changed field:email, at, field, old_value, new_value, source(panel | tgbot | auto-renew), indexed by email+time.Where windows are archived (same transaction as the zeroing/deletion, so nothing is lost or double-counted):
reason: resetautoRenewClients) archives the closed quota window and logs the expiry change —reason: renew, sourceauto-renewdeletedevent —reason: deleted. The final row cleanup of a delete re-checks for any counter row that no per-inbound path archived (a client shared with an inbound outside the delete, or detached from every inbound) and archives it there too, so every dropped counter lands in exactly one window — never zero, never two.reason: renamedWhere changes are logged:
POST /clients/update/:email— diffs the old record against the saved one and logs only the fields that actually changed (panel).tgbot).panel).Read side:
GET /clients/usageHistory/:emailreturns lifetime totals (SUM over all archived windows + live row), the open window's counters, the closed windows (newest first, capped at 2000 rows — the totals still count every row), the per-node up/down joined with node names, and the change log (newest first, capped at 500). Documented in the API-docs registry with a generatedClientUsageHistoryresponse schema; the generated OpenAPI spec, its docs copy, and the docs reference page are regenerated. Unknown future fields/reasons render raw instead of blank.UI: a labeled Usage & change history button in the edit modal's footer (edit mode, client with an email) opens a nested modal with the lifetime totals (upload/download + current cycle), a per-node table with separate ↑/↓ columns, the closed-cycles table, and the change log with human labels for every field in all 14 locales. Fetching uses the house react-query pattern (per-email cache, enabled only while the modal is open).
How was this tested?
client_usage_history_test.go): a single-client reset archives aresetwindow and lifetime = archived + live; bulk reset archives only rows with real usage; an auto-renewal archives arenewwindow and logs the expiry change underauto-renew; deletion archives adeletedwindow and logs the event; deleting an attached client archives its counters exactly once (the per-inbound path handles them, the final cleanup sees nothing left); deleting a detached client archives the surviving counters in the final cleanup; a bulk delete archives onedeletedwindow + one event per email; a rename archives the discarded counters underrenamedwithout a deletion event; an editor save logs exactly the changed fields and a no-op save logs nothing; bulk enable/disable logs only the flipped clients; a rename migrates every window and log row to the new email and records the rename once; an empty client reads back all zeros with empty collections; a node's counters come back separated into upload/download with the node's name; the endpoint's JSON shape carries all eight top-level keys.renewreason, and shows the empty state.go-testsuite over every package; (2) a-racerun over the touched packages plus the new tests twice; (3) both Postgres CI gate test sets against a UTF8 Postgres 17 instance (CI uses 16). The pinnedgolangci-lintv2.15.0, gofumpt/goimports, and the frontend lint/format/typecheck/vitest gates pass as well. Two local-only caveats, both reproduced on cleanmainso they are not from this PR: a small set of frontend locale tests time out on this Windows box, and one-racetest binary fails to load (STATUS_ENTRYPOINT_NOT_FOUND).Breaking changes
None. The two new tables are additive (auto-migrated, empty on upgrade); existing clients read back as "no history yet" until their next reset/renewal/edit. Archived windows only cover usage closed after the upgrade — pre-existing
client_traffics.up/downis not back-filled, so a long-lived panel's lifetime total starts from the upgrade point.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.