(w http.ResponseWriter, r *http.Request, nodeID string)
| 600 | } |
| 601 | |
| 602 | func (a *API) handleNodeApply(w http.ResponseWriter, r *http.Request, nodeID string) { |
| 603 | if r.Method != http.MethodPost { |
| 604 | writeMethodNotAllowed(w, http.MethodPost) |
| 605 | return |
| 606 | } |
| 607 | if a.usersStore == nil || a.inboundStore == nil { |
| 608 | writeJSON(w, http.StatusInternalServerError, map[string]any{"error": "stores not configured"}) |
| 609 | return |
| 610 | } |
| 611 | client, err := a.clientFor(nodeID) |
| 612 | if err != nil { |
| 613 | writeNodeError(w, err) |
| 614 | return |
| 615 | } |
| 616 | nodeInbounds, err := a.inboundStore.ListInboundsByNode(nodeID) |
| 617 | if err != nil { |
| 618 | writeJSON(w, http.StatusInternalServerError, map[string]any{"error": err.Error()}) |
| 619 | return |
| 620 | } |
| 621 | userAccesses, err := a.usersStore.ListUserInboundsByNode(nodeID) |
| 622 | if err != nil { |
| 623 | writeJSON(w, http.StatusInternalServerError, map[string]any{"error": err.Error()}) |
| 624 | return |
| 625 | } |
| 626 | userIDs := collectNodeUserIDs(userAccesses) |
| 627 | userMap, err := a.usersStore.GetUsersByIDs(userIDs) |
| 628 | if err != nil { |
| 629 | writeJSON(w, http.StatusInternalServerError, map[string]any{"error": err.Error()}) |
| 630 | return |
| 631 | } |
| 632 | node, err := a.store.Get(nodeID) |
| 633 | if err != nil { |
| 634 | writeJSON(w, http.StatusInternalServerError, map[string]any{"error": err.Error()}) |
| 635 | return |
| 636 | } |
| 637 | ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second) |
| 638 | defer cancel() |
| 639 | status, _, err := jobs.ApplyNodeUsers(ctx, client, nodeInbounds, userAccesses, userMap, a.inboundStore, a.outboundStore, a.applyOpts, node) |
| 640 | if err != nil { |
| 641 | writeJSON(w, http.StatusUnprocessableEntity, map[string]any{"error": err.Error()}) |
| 642 | return |
| 643 | } |
| 644 | writeJSON(w, http.StatusOK, status) |
| 645 | } |
| 646 | |
| 647 | // TriggerNodeSync 异步触发指定节点的 NodeGate sync。 |
| 648 |
no test coverage detected