handleAccessApply 将该节点的完整配置重新下发。
(w http.ResponseWriter, r *http.Request, userID, ibID string)
| 509 | |
| 510 | // handleAccessApply 将该节点的完整配置重新下发。 |
| 511 | func (a *userAPI) handleAccessApply(w http.ResponseWriter, r *http.Request, userID, ibID string) { |
| 512 | if r.Method != http.MethodPost { |
| 513 | writeMethodNotAllowed(w, http.MethodPost) |
| 514 | return |
| 515 | } |
| 516 | acc, err := a.users.GetUserInbound(ibID) |
| 517 | if err != nil { |
| 518 | writeUserInboundError(w, err) |
| 519 | return |
| 520 | } |
| 521 | if acc.UserID != userID { |
| 522 | writeJSON(w, http.StatusNotFound, map[string]any{"error": "user inbound not found"}) |
| 523 | return |
| 524 | } |
| 525 | |
| 526 | nodeInbounds, err := a.inboundStore.ListInboundsByNode(acc.NodeID) |
| 527 | if err != nil { |
| 528 | internalError(w, r, err) |
| 529 | return |
| 530 | } |
| 531 | allAccesses, err := a.users.ListUserInboundsByNode(acc.NodeID) |
| 532 | if err != nil { |
| 533 | internalError(w, r, err) |
| 534 | return |
| 535 | } |
| 536 | userIDs := collectUserIDs(allAccesses) |
| 537 | userMap, err := a.users.GetUsersByIDs(userIDs) |
| 538 | if err != nil { |
| 539 | internalError(w, r, err) |
| 540 | return |
| 541 | } |
| 542 | |
| 543 | client, err := a.base.clientFor(acc.NodeID) |
| 544 | if err != nil { |
| 545 | writeNodeError(w, err) |
| 546 | return |
| 547 | } |
| 548 | accNode, _ := a.base.store.Get(acc.NodeID) |
| 549 | ctx, cancel := context.WithTimeout(r.Context(), 10*time.Second) |
| 550 | defer cancel() |
| 551 | |
| 552 | status, config, err := jobs.ApplyNodeUsers(ctx, client, nodeInbounds, allAccesses, userMap, a.inboundStore, a.outboundStore, a.applyOpts, accNode) |
| 553 | if err != nil { |
| 554 | writeJSON(w, http.StatusBadGateway, map[string]any{"error": err.Error()}) |
| 555 | return |
| 556 | } |
| 557 | |
| 558 | writeJSON(w, http.StatusOK, map[string]any{ |
| 559 | "access": acc, |
| 560 | "users_count": len(allAccesses), |
| 561 | "active_users": len(filterEnabledAccesses(allAccesses, userMap)), |
| 562 | "node_status": status, |
| 563 | "node_config": json.RawMessage(config), |
| 564 | }) |
| 565 | } |
| 566 | |
| 567 | // handleAccessSubscription 返回该节点访问凭据对应的所有订阅链接。 |
| 568 | func (a *userAPI) handleAccessSubscription(w http.ResponseWriter, r *http.Request, userID, ibID string) { |
no test coverage detected