(w http.ResponseWriter, r *http.Request, nodeID string)
| 657 | } |
| 658 | |
| 659 | func (a *API) handleNodeSpeedTest(w http.ResponseWriter, r *http.Request, nodeID string) { |
| 660 | if r.Method != http.MethodPost { |
| 661 | writeMethodNotAllowed(w, http.MethodPost) |
| 662 | return |
| 663 | } |
| 664 | client, err := a.clientFor(nodeID) |
| 665 | if err != nil { |
| 666 | writeNodeError(w, err) |
| 667 | return |
| 668 | } |
| 669 | ctx, cancel := context.WithTimeout(r.Context(), 70*time.Second) |
| 670 | defer cancel() |
| 671 | resp, err := client.SpeedTest(ctx) |
| 672 | if err != nil { |
| 673 | writeJSON(w, http.StatusUnprocessableEntity, map[string]any{"error": err.Error()}) |
| 674 | return |
| 675 | } |
| 676 | result := nodes.SpeedTestResult{ |
| 677 | DownBps: resp.DownBps, |
| 678 | UpBps: resp.UpBps, |
| 679 | TestedAt: time.Now().UTC(), |
| 680 | } |
| 681 | _ = a.store.UpsertNodeSpeedTest(nodeID, result) |
| 682 | writeJSON(w, http.StatusOK, result) |
| 683 | } |
| 684 | |
| 685 | func (a *API) handleNodeCheck(w http.ResponseWriter, r *http.Request, nodeID string) { |
| 686 | if r.Method != http.MethodPost { |
no test coverage detected