mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6571] [CLOSED] feat(links): make external links a panel-wide library with scopes #6358
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#6358
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/6571
Author: @BlindMaster24
Created: 9/16/2026
Status: ❌ Closed
Base:
main← Head:feat/external-links-library📝 Commits (1)
5afa867feat(links): make external links a panel-wide library with scopes📊 Changes
42 files changed (+6346 additions, -322 deletions)
View changed files
📝
docs/content/docs/en/reference/api/clients.mdx(+29 -21)➕
docs/content/docs/en/reference/api/external-links.mdx(+122 -0)📝
docs/public/openapi.json(+1069 -2)📝
frontend/public/openapi.json(+1069 -2)📝
frontend/src/generated/examples.ts(+69 -0)📝
frontend/src/generated/schemas.ts(+338 -0)📝
frontend/src/generated/types.ts(+74 -0)📝
frontend/src/generated/zod.ts(+79 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+275 -3)📝
internal/database/db.go(+88 -28)➕
internal/database/external_link_library_migration_test.go(+159 -0)📝
internal/database/migrate_data.go(+2 -1)📝
internal/database/model/model.go(+82 -0)📝
internal/sub/clash_external_quota_test.go(+2 -6)📝
internal/sub/external_config.go(+52 -33)➕
internal/sub/external_link_flow_test.go(+244 -0)➕
internal/sub/external_link_testseed_test.go(+52 -0)📝
internal/sub/external_only_sub_test.go(+1 -3)📝
internal/sub/external_subscription.go(+326 -75)📝
internal/sub/external_subscription_test.go(+64 -46)...and 22 more files
📄 Description
What this is
Turns external links from a per-client list into a panel-wide library with scopes, and makes the panel a conforming client when it fetches someone else's subscription.
Today a link can only belong to one client (
client_external_links.client_id), so "the same backup provider for 300 clients" is 300 copies that drift, and none of the requests behind it (#5533, #6022, #5293, #5694) can be built on top.Model
external_links— the shared row:kind(link/subscription),value,remark,namePrefix,enable,expiryTime,sortIndex, its own fetch identity (userAgent,headers,cacheTtl) and the last good expansion (lastLinks). Unique on(kind, value).external_link_assignments— binds a library row to a target withtargetType=client/group/inbound/global/new_clients, plus per-binding overrides (enable,expiryTime,remark,namePrefix,sortIndex). Unique on(link_id, target_type, target_id).expiryTimethere is-1(never) /0(inherit) / a timestamp, because a client's own "never" has to stay distinguishable from inheriting a shared expiry.migrateClientExternalLinksToLibraryis idempotent: one library row per distinct(kind, value), one assignment per legacy row keeping that client's own overrides, order and expiry, then the legacy table is retired asclient_external_links_legacy. No client's expiry is copied onto the shared row.Fetch layer (
internal/sub)If-None-Match/If-Modified-Since; a304refreshes the entry nearly for free.Retry-After, plus jitter and a per-host bound that covers only background revalidations, so a wave after a restart does not serialise behind them.lastLinks) is read back when a fetch yields nothing, so a restart with the provider down still serves the client.X-HWIDthe panel sends is the mechanism merged in #6567 (serverHwid, persisted per installation), which is the fix for the404from an HWID-limited donor (#6559); this PR builds on it rather than duplicating it. Per-rowheadersare layered on top.Wiring
GET/POST /panel/api/links/{list,add,del/:id,enable/:id,reorder,targets/:id,assign/:id,unassign/:id,client/:clientId,refresh/:id}, registered ininternal/web/controller/link.go, documented inendpoints.ts,openapi.jsonregenerated,docs/reference page regenerated.ExportAll/ImportClientsare used only by the panel's export/import endpoints, so those links stay panel-local and are never pushed to a node.new_clientsscope through a batched materialise on creation and on bulk creation.Review round 1
Nine findings were posted and each has a disposition in this reply: both HIGHs (the usage aggregate had no
GROUP BY; an assignment could not express "never expires") and the MEDIUMs (last_linkswas written but never read, stale generated output, a partial library edit resetting order and identity, a DB read on the fetch path without a nil guard, the host gate serialising the cold wave) are fixed, and the LOW documentation gap is closed. Each fix that can be tested carries a test that fails without it.While re-reading the same code one more such hole was found and fixed before the review reached it: a body that omits
enableused to re-enable a disabled row, so a "rename only" edit flipped its state.Verification
CI on this branch:
build(386, amd64, arm64, armv5/6/7, s390x) andBuild for Windows,go-test,race,golangci,govulncheck,fuzz-smoke,codegen,frontend,postgres-durable-first,CodeQLandDocs CI— all green.What the local machine could and could not do, plainly: this workstation has no C toolchain and its commit limit is exhausted, so
go build/go test/golangci-lintdie without of memory allocating heap arena map— no local Go build or test run happens for this branch at all, which is why every test here is proven by CI rather than by me. What was run locally:gofmt -e -lon every touched file, the unused-import and comment-cap checks,go run ./tools/openapigen+node scripts/build-openapi.mjs+ the docs generator (all of which produced the committed output), and the route ⇄endpoints.ts⇄openapi.jsoncomparison.Still unverified by any job: the PostgreSQL dialect run beyond
postgres-durable-first(which runs a single test), so theGROUP BYfix rests on PostgreSQL's documented rule plus a SQLite-executed test, not on an executed Postgres query. The Xray gRPC end-to-end tests needXRAY_E2E_BINARY, which CI does not set; this change does not touch that path.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.