MCPcopy Index your code
hub / github.com/0xUnixIO/pulse / handleNodeApply

Method handleNodeApply

internal/serverapi/api.go:602–645  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, nodeID string)

Source from the content-addressed store, hash-verified

600}
601
602func (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

Callers 1

handleNodeRoutesMethod · 0.95

Calls 11

clientForMethod · 0.95
ApplyNodeUsersFunction · 0.92
writeMethodNotAllowedFunction · 0.85
writeNodeErrorFunction · 0.85
collectNodeUserIDsFunction · 0.85
writeJSONFunction · 0.70
ListInboundsByNodeMethod · 0.65
GetUsersByIDsMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected