mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6599] [CLOSED] feat(links): replicate the master's library onto its nodes #6370
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#6370
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/6599
Author: @BlindMaster24
Created: 9/18/2026
Status: ❌ Closed
Base:
main← Head:feat/external-links-node-sync📝 Commits (10+)
5afa867feat(links): make external links a panel-wide library with scopeseac7ef0feat(links): add the panel-side UI for the external links librarya82ce6dfeat(links): replicate the master's library onto its nodesc2547e1fix(nodes): let a node-scoped token reach the link sync endpointfad5981fix(nodes): bound the link push by the reconcile's own deadline2e094b7perf(links): mark the nodes dirty instead of pushing on a library edite17a383chore(links): drop the unused non-transactional MarkAllNodesDirtyad51f67test(links): cover the assign surface and the Clash link rendering51faacdtest(links): cover the node-sync endpoints, the push wire and the Clash kinds7e64616fix(links): store an edited row's headers as the JSON the column holds📊 Changes
82 files changed (+13944 additions, -2866 deletions)
View changed files
📝
docs/content/docs/en/reference/api/clients.mdx(+29 -21)➕
docs/content/docs/en/reference/api/external-links.mdx(+133 -0)📝
docs/public/openapi.json(+2543 -1273)📝
frontend/public/openapi.json(+2543 -1273)➕
frontend/src/api/queries/useGroupOptions.ts(+22 -0)➕
frontend/src/api/queries/useLinkMutations.ts(+85 -0)➕
frontend/src/api/queries/useLinksQuery.ts(+80 -0)📝
frontend/src/api/queryKeys.ts(+6 -0)📝
frontend/src/generated/examples.ts(+137 -0)📝
frontend/src/generated/schemas.ts(+466 -0)📝
frontend/src/generated/types.ts(+109 -0)📝
frontend/src/generated/zod.ts(+120 -0)📝
frontend/src/layouts/AppSidebar.tsx(+5 -1)📝
frontend/src/lib/clients/external-link.ts(+13 -0)📝
frontend/src/pages/api-docs/endpoints.ts(+283 -3)📝
frontend/src/pages/clients/ClientFormModal.tsx(+42 -1)➕
frontend/src/pages/links/LinkFormModal.tsx(+148 -0)➕
frontend/src/pages/links/LinkTargetsModal.tsx(+194 -0)➕
frontend/src/pages/links/LinksPage.tsx(+362 -0)📝
frontend/src/routes.tsx(+2 -0)...and 62 more files
📄 Description
What this is
Delivery C of the external-links plan: the master's library now reaches its nodes.
The diff therefore contains A and B as well while they are open; once they land, this
PR collapses to the C commit. Nothing here is merged.
Why it is needed
internal/subruns on every panel, node included, and resolves external links from thelocal store (
external_config.go:68). A node has no library, no scopes and no groups —groups are not replicated to nodes at all — so a client whose links were granted by a group
or by the global scope received none of them when its subscription was fetched from a node.
What it does
ExternalLinkSyncForNoderesolves the effective set for one node and flattensgroup/inbound scopes into per-client bindings, because the node cannot evaluate a scope it
does not hold.
PushExternalLinksToNode(s)sends it; a per-client add or edit sends onlythe clients it touched.
POST /panel/api/links/syncmaterialises the snapshot — upsert bykind+value, replace only the bindings carryingorigin=node,dropUnusedPushedExternalLinksretires rows nobody inherits.
(
SetExternalLinksForRecord), so an operator editing on a node cannot contradict the master.ReconcileNodere-pushes on the same sweep that already converges thenode's inbounds, so an offline or hung node catches up by itself.
The defects this change found and fixed, and fixed here
TestNodePushGivesUpBeforeTheRemoteTimeout(pre-existing,a5e68f41) went red withthe first version: the per-client edit path spent the pushed-link deadline on a node that
had just refused the client push — 8.01s against a hung node instead of the 4s bound.
The edit path now clears
pushon a failed push, exactly as the add path already did, andthe node's already-set dirty flag converges it. Red 8.23s → green 4.28s, same command.
the node's own bearer token, whose scope is
node-sync(
internal/web/runtime/remote.go:233-237), andenforceTokenScopedenies anode-synccaller whose route is not in
nodeSyncScopeAllow(internal/web/controller/api.go:146)./panel/api/links/syncwas missing from that allowlist, so every push was answered403 "this API token is not permitted to access this endpoint" and the links never
landed — while all of the delivery's own tests passed, because they call the transport
directly and never meet the middleware.
TestNodeSyncScopeUsesFullPathPatternsnow drivesthe route through the real auth chain: 403 before the entry, 200 after.
/panel/api/links/syncaccepted anykind/value, while/links/addvalidates both;a push could store a link this panel would have refused. The same validation now runs on
the receiving side.
ReconcileNodehands over a context carrying its timeout and every call it makes honoursit; the link push built a fresh four-second deadline of its own instead, so a reconcile that
had already given up kept spending its budget on that node.
PushExternalLinksToNodenowtakes the caller's context (
TestPushExternalLinksHonoursTheCallersDeadline: with thecaller's context cancelled the fake node received the request, and now receives none).
Verification
gofmtclean;golangci-lintis not installed on this machine, so Go lint is left to CI.CGO_ENABLED=0with the pure-Go SQLite overlay (this box has no C compiler):internal/web/serviceok 139s,internal/web/runtime/controller/web(routecontract) /
job/internal/subok,internal/databasemigration tests ok.Re-run after the 403 fix:
internal/web/controllerok 9.8s,internal/webok 0.6s.The CGo-only database tests (
backup_test.go,dump_sqlite_test.go,*_index_test.go,inbound_port_unique_migration_test.go) cannot run here at all — the overlay replaces the驱动 they open directly — so they are unverified locally and left to CI.
tsc --noEmit,oxlint,oxfmt --checkclean,vite buildok,vitest --project unit78/80 files,--project storybook26/27.The three failures are this machine, not the change, each with evidence:
input-number-guardfails becausenode_modulesholds oxlint 1.82.0 whilepackage.jsonpins 1.83.0 (the rule landed in 1.83);language-scopepasses when runalone (3.4s) and only exceeds its 5s limit under the full parallel run;
FormField.stories > Traffic Transformexpects en-US grouping and the host browser isru-RU. None of the three files is in this diff, and CI'sfrontendjob is green.endpoints.ts,npm run gen,docs/public/openapi.jsoncopied over andpnpm gen:apire-run.Propagation is level-triggered
A library edit marks every enabled node dirty inside the write's own transaction and lets the
5s reconcile sweep push the set; it never waits on a node. That is the design this panel
already documents for every other node-backed edit (
node.go'sIsNodePendingcomment: theflag "is set on EVERY node-backed edit as the reconcile self-heal marker"), and it is the only
thing that also converges a node that happens to be down during the edit. The push itself was
already wired into
ReconcileNode, so no second propagation path exists.TestLibraryEditsDeferToTheReconcileSweep: on a hanging node the edit took 4.006s before thischange and returns in 0.24s now, leaves the node dirty, and the reconcile delivers exactly one
push.
Tests for the write path
The library's own write path had no service-level test, so it was covered next:
assignis asserted to bind five targets from one request and four clients areasserted to resolve through four different scopes (client, inbound, group, global) - the
precedence rule driven through the real resolver.
assign creates it, that re-assigning refreshes overrides in place, and that unassigning a
client leaves the group's binding alone.
AppliedPushedRowsAreReadOnlygained reorder; apply is asserted all-or-nothing; apositive deadline survives a push while 0 stays "never"; a save during boot (no runtime
manager) does not panic.
internal/sub: Clash rendering for hysteria2 and wireguard library rows, the host/portsplit behind it, and
Retry-Afterparsing.Coverage moved from 64.9% to 65.9% in
internal/web/service(ExternalLinkAssign0 -> 94.7,Unassign0 -> 92.3,Targets0 -> 86.2,ClientExternalLinkViews0 -> 85.0) and from 85.2%to 86.2% in
internal/sub(clashHysteriaFromExternal0 -> 100,clashWireguardFromExternal0 -> 95.8,splitClashHostPort0 -> 100,parseRetryAfter27.3 -> 100). Three mutation checks were run and reverted to prove the tests bite.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.