[PR #6908] [MERGED] feat(api): add client lookup by subscription ID #6514

Closed
opened 2026-11-02 04:09:19 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6908
Author: @Maximora-byte
Created: 10/23/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei

Base: main ← Head: feat/api-client-by-subid


📝 Commits (3)

  • c7fc398 feat(api): add client lookup by subscription ID
  • 8372cb1 fix(api): allow null in subscription lookup response schema
  • b61de2a Merge remote-tracking branch 'origin/main' into pr/6908

📊 Changes

6 files changed (+369 additions, -1 deletions)

View changed files

📝 docs/content/docs/en/reference/api/clients.mdx (+13 -1)
📝 docs/public/openapi.json (+75 -0)
📝 frontend/public/openapi.json (+75 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+29 -0)
📝 internal/web/controller/client.go (+23 -0)
➕ internal/web/controller/client_lookup_test.go (+154 -0)

📄 Description

Summary

Add GET /panel/api/clients/get/subId/:subId to retrieve full client records directly from an exact subscription ID. The response includes the same client, inbound IDs, external links, traffic usage and tunnel addresses as the existing email lookup.

Why

Closes #6792.

The requested /links/:subId path would collide with /links/:email, so this follows the existing /get/tgId/:tgId layout. It reuses GetRecordsBySubID and buildClientPayload.

The response is an array, including disabled, expired and unattached records, ordered by client ID. The existing schema and lookup service explicitly support shared subscription IDs, and inbound synchronization can preserve them; returning only the first record would lose clients. An unknown ID uses the email lookup's HTTP 200 success:false, obj:null, record-not-found convention. The OpenAPI response object is nullable to cover that error envelope.

The route remains behind the existing session/admin-token authentication. Monitor, node-sync and node-admin tokens cannot retrieve these credentials. No migration or runtime dispatch change is needed.

Type of change

  • New feature
  • Documentation

Areas affected

  • Backend (API endpoints, login, settings)
  • Frontend (in-panel API reference only)

How was this tested?

  • Red/green: TestClientGetBySubIDHTTP returned 404 against the original router, then passed after the route was implemented.
  • Real SQLite and Gin HTTP tests cover exact matches with literal %/_, shared and single IDs, partial/wildcard/missing IDs, disabled orphans, inbound/flow/traffic payloads, and anonymous/admin/restricted-token access.
  • Linux container, Go 1.27.3: go test -p 4 -shuffle=on -count=1 ./... (50 packages with tests passed), go build -p 4 ./..., and golangci-lint 2.15.0 (0 issues).
  • TestRouteRegistryContract passed. Regenerated Go schemas/examples/types/Zod match the committed files. Both OpenAPI copies and the client API MDX were regenerated.
  • Node 26.12.1: the full frontend suite (189 files, 1852 tests), lint, typecheck, format check, production build and Storybook build passed on the feature commit. After the nullable-schema follow-up, the two OpenAPI test files (8 tests), lint, typecheck, format check and production build were rerun successfully.
  • One-off OpenAPI 3.0 contract validation: the not-found envelope (obj:null) and an array response validate, while a string response is rejected.
  • Docs: pnpm 12.9.1 with pnpm install --frozen-lockfile; codegen, typecheck, lint, format check, tests (12 files, 107 tests) and production build passed. The build used an HTTP proxy to fetch the site's existing Google Fonts.

Go validation ran in Linux. The Go suite's opt-in live PostgreSQL, Xray gRPC, master/node and scale tests were not enabled.

Screenshots / recordings

Not applicable: API and reference-documentation change; no panel controls or layout changes.

Breaking changes

None. Existing lookup and link routes are unchanged.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added tests for the new behavior.
  • Go build and test suite pass locally in Linux.
  • Frontend lint, typecheck and build pass.
  • I updated the in-panel and documentation-site API references.
  • My commit follows the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6908 **Author:** [@Maximora-byte](https://github.com/Maximora-byte) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/api-client-by-subid` --- ### 📝 Commits (3) - [`c7fc398`](https://github.com/MHSanaei/3x-ui/commit/c7fc3985a3a7965abefeace4a8da4cdd7644e100) feat(api): add client lookup by subscription ID - [`8372cb1`](https://github.com/MHSanaei/3x-ui/commit/8372cb1efbb12caaed0b136fd0987eaff9b772df) fix(api): allow null in subscription lookup response schema - [`b61de2a`](https://github.com/MHSanaei/3x-ui/commit/b61de2adf201bbce400f84a6db2baeecdb505a57) Merge remote-tracking branch 'origin/main' into pr/6908 ### 📊 Changes **6 files changed** (+369 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/reference/api/clients.mdx` (+13 -1) 📝 `docs/public/openapi.json` (+75 -0) 📝 `frontend/public/openapi.json` (+75 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+29 -0) 📝 `internal/web/controller/client.go` (+23 -0) ➕ `internal/web/controller/client_lookup_test.go` (+154 -0) </details> ### 📄 Description ## Summary Add `GET /panel/api/clients/get/subId/:subId` to retrieve full client records directly from an exact subscription ID. The response includes the same client, inbound IDs, external links, traffic usage and tunnel addresses as the existing email lookup. ## Why Closes #6792. The requested `/links/:subId` path would collide with `/links/:email`, so this follows the existing `/get/tgId/:tgId` layout. It reuses `GetRecordsBySubID` and `buildClientPayload`. The response is an array, including disabled, expired and unattached records, ordered by client ID. The existing schema and lookup service explicitly support shared subscription IDs, and inbound synchronization can preserve them; returning only the first record would lose clients. An unknown ID uses the email lookup's HTTP 200 `success:false`, `obj:null`, record-not-found convention. The OpenAPI response object is nullable to cover that error envelope. The route remains behind the existing session/admin-token authentication. Monitor, node-sync and node-admin tokens cannot retrieve these credentials. No migration or runtime dispatch change is needed. ## Type of change - [x] New feature - [x] Documentation ## Areas affected - [x] Backend (API endpoints, login, settings) - [x] Frontend (in-panel API reference only) ## How was this tested? - Red/green: `TestClientGetBySubIDHTTP` returned 404 against the original router, then passed after the route was implemented. - Real SQLite and Gin HTTP tests cover exact matches with literal `%`/`_`, shared and single IDs, partial/wildcard/missing IDs, disabled orphans, inbound/flow/traffic payloads, and anonymous/admin/restricted-token access. - Linux container, Go 1.27.3: `go test -p 4 -shuffle=on -count=1 ./...` (50 packages with tests passed), `go build -p 4 ./...`, and golangci-lint 2.15.0 (`0 issues`). - `TestRouteRegistryContract` passed. Regenerated Go schemas/examples/types/Zod match the committed files. Both OpenAPI copies and the client API MDX were regenerated. - Node 26.12.1: the full frontend suite (189 files, 1852 tests), lint, typecheck, format check, production build and Storybook build passed on the feature commit. After the nullable-schema follow-up, the two OpenAPI test files (8 tests), lint, typecheck, format check and production build were rerun successfully. - One-off OpenAPI 3.0 contract validation: the not-found envelope (`obj:null`) and an array response validate, while a string response is rejected. - Docs: pnpm 12.9.1 with `pnpm install --frozen-lockfile`; codegen, typecheck, lint, format check, tests (12 files, 107 tests) and production build passed. The build used an HTTP proxy to fetch the site's existing Google Fonts. Go validation ran in Linux. The Go suite's opt-in live PostgreSQL, Xray gRPC, master/node and scale tests were not enabled. ## Screenshots / recordings Not applicable: API and reference-documentation change; no panel controls or layout changes. ## Breaking changes None. Existing lookup and link routes are unchanged. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added tests for the new behavior. - [x] Go build and test suite pass locally in Linux. - [x] Frontend lint, typecheck and build pass. - [x] I updated the in-panel and documentation-site API references. - [x] My commit follows the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:19 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6514
No description provided.