mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6380] [MERGED] feat(sub): add read-only HWID device-slot status endpoint #6242
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#6242
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/6380
Author: @Namso9
Created: 8/31/2026
Status: ✅ Merged
Merged: 9/11/2026
Merged by: @MHSanaei
Base:
main← Head:feat/sub-hwid-status📝 Commits (3)
01cf1f3feat(sub): add read-only HWID device-slot status endpoint8280ef4Merge branch 'main' into pr/63805aff5a6fix(sub): document hwid-status as the bare object it returns📊 Changes
15 files changed (+637 additions, -3 deletions)
View changed files
📝
docs/content/docs/en/reference/api/subscription-server.mdx(+27 -2)📝
docs/public/openapi.json(+126 -0)📝
frontend/public/openapi.json(+126 -0)📝
frontend/scripts/build-openapi.mjs(+18 -1)📝
frontend/src/generated/examples.ts(+7 -0)📝
frontend/src/generated/schemas.ts(+33 -0)📝
frontend/src/generated/types.ts(+8 -0)📝
frontend/src/generated/zod.ts(+9 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+34 -0)📝
frontend/src/test/openapi-runtime-contracts.test.ts(+15 -0)📝
internal/sub/controller.go(+14 -0)📝
internal/sub/hwid_controller_test.go(+112 -0)📝
internal/web/service/client_hwid.go(+49 -0)📝
internal/web/service/client_hwid_test.go(+58 -0)📝
tools/openapigen/main.go(+1 -0)📄 Description
Closes #6357
What
Adds one additive, public, read-only endpoint on the subscription router, as requested in #6357:
A subscriber (or a customer-facing panel / reseller bot built on the subscription API) can now show "Devices 1/2 — 1 slot remaining" instead of a silently failing connection.
Behaviour
last_seen, and never callsEnforceHwidForSubID, so asking about a slot cannot spend one. A test assertsclient_hwidsstays empty after a probe that carriesX-HWID, and that the next real fetch with that same HWID still succeeds.X-Hwid-*gate headers. The test decodes into a map and asserts the exact field set, so an added field fails./{subPath}/{subId}.404, and a test asserts identical status, headers and body.{"active":false,"limit":0,"registered":0,"remaining":0,"full":false}./{subPath}/{subId},?format=info, and the JSON/Clash routes are not modified at all.Notes for reviewers
HwidSlotStatusForSubIDscopes the limit through the existingeffectiveHwidLimitForSubIDhelper (enabled clients,MAX(limit_hwid)), so the reported limit is always the enforced limit on a sharedsub_id. That is also why existence is "≥1 enabled client with this sub_id" — the same notion the gate uses — rather than the body route's "enabled inbound joined to the sub_id".remainingclamps at zero: deleting or disabling the highest-limit client of a sharedsub_idlowers the effectiveMAXwithout trimming rows, soregistered > limitis reachable. Covered by a test.HEADis registered alongsideGET, matching the sibling subscription routes.frontend/src/pages/api-docs/endpoints.ts,make genwas run, andfrontend/public/openapi.json→docs/public/openapi.json+cd docs && pnpm gen:apiwere regenerated. The response is documented in prose becausebuild-openapi.mjswraps every operation in the{success,msg,obj}panel envelope, which does not apply to subscription-server routes.How to test
Manually, with a client that has
limitHwid = 1:Checks run locally
go build ./...,go vet,go test -shuffle=on -count=1 ./...,go test -race -shuffle=on ./internal/sub/ ./internal/web/service/, frontendtypecheck/lint/format:check, andmake genreproducing the committed generated files. (internal/mtproto's two process-spawn timing tests flaked once on a loaded laptop and pass on a re-run; they are untouched by this change.)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.