handleSubLogs 返回用户的订阅访问日志。
(w http.ResponseWriter, r *http.Request, userID string)
| 894 | |
| 895 | // handleSubLogs 返回用户的订阅访问日志。 |
| 896 | func (a *userAPI) handleSubLogs(w http.ResponseWriter, r *http.Request, userID string) { |
| 897 | if r.Method != http.MethodGet { |
| 898 | writeJSON(w, http.StatusMethodNotAllowed, map[string]any{"error": "method not allowed"}) |
| 899 | return |
| 900 | } |
| 901 | limit := 50 |
| 902 | if v, err := strconv.Atoi(r.URL.Query().Get("limit")); err == nil && v > 0 && v <= 200 { |
| 903 | limit = v |
| 904 | } |
| 905 | logs, err := a.users.ListSubAccessLogs(userID, limit) |
| 906 | if err != nil { |
| 907 | internalError(w, r, fmt.Errorf("failed to list sub logs: %w", err)) |
| 908 | return |
| 909 | } |
| 910 | writeJSON(w, http.StatusOK, map[string]any{"logs": logs}) |
| 911 | } |
| 912 | |
| 913 | func (a *userAPI) handleNodeUsage(w http.ResponseWriter, r *http.Request, userID string) { |
| 914 | if r.Method != http.MethodGet { |
no test coverage detected