(w http.ResponseWriter, r *http.Request)
| 157 | } |
| 158 | |
| 159 | func (a *userAPI) handleUserRoutes(w http.ResponseWriter, r *http.Request) { |
| 160 | path := strings.TrimPrefix(r.URL.Path, "/v1/users/") |
| 161 | parts := strings.Split(path, "/") |
| 162 | if len(parts) == 0 || parts[0] == "" { |
| 163 | writeJSON(w, http.StatusNotFound, map[string]any{"error": "user id is required"}) |
| 164 | return |
| 165 | } |
| 166 | |
| 167 | userID := parts[0] |
| 168 | switch len(parts) { |
| 169 | case 1: |
| 170 | a.handleUser(w, r, userID) |
| 171 | case 2: |
| 172 | switch parts[1] { |
| 173 | case "inbounds": |
| 174 | a.handleUserInbounds(w, r, userID) |
| 175 | case "reset-traffic": |
| 176 | a.handleResetTraffic(w, r, userID) |
| 177 | case "sub-logs": |
| 178 | a.handleSubLogs(w, r, userID) |
| 179 | case "node-usage": |
| 180 | a.handleNodeUsage(w, r, userID) |
| 181 | case "credentials": |
| 182 | a.handleUserCredentials(w, r, userID) |
| 183 | case "regenerate-sub-token": |
| 184 | a.handleRegenerateSubToken(w, r, userID) |
| 185 | default: |
| 186 | writeJSON(w, http.StatusNotFound, map[string]any{"error": "route not found"}) |
| 187 | } |
| 188 | case 3: |
| 189 | if parts[1] == "inbounds" { |
| 190 | a.handleUserInbound(w, r, userID, parts[2]) |
| 191 | } else { |
| 192 | writeJSON(w, http.StatusNotFound, map[string]any{"error": "route not found"}) |
| 193 | } |
| 194 | case 4: |
| 195 | if parts[1] == "inbounds" { |
| 196 | ibID := parts[2] |
| 197 | switch parts[3] { |
| 198 | case "apply": |
| 199 | a.handleAccessApply(w, r, userID, ibID) |
| 200 | case "subscription": |
| 201 | a.handleAccessSubscription(w, r, userID, ibID) |
| 202 | default: |
| 203 | writeJSON(w, http.StatusNotFound, map[string]any{"error": "route not found"}) |
| 204 | } |
| 205 | } else { |
| 206 | writeJSON(w, http.StatusNotFound, map[string]any{"error": "route not found"}) |
| 207 | } |
| 208 | default: |
| 209 | writeJSON(w, http.StatusNotFound, map[string]any{"error": "route not found"}) |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | func (a *userAPI) handleUser(w http.ResponseWriter, r *http.Request, userID string) { |
| 214 | switch r.Method { |
nothing calls this directly
no test coverage detected