GET /admin/api/v1/characters/{characterName} Returns the full character record for the named character. The character index is consulted first to resolve the owning user, then the user record is loaded (online cache first, then disk) to retrieve the character data.
(w http.ResponseWriter, r *http.Request)
| 45 | // index is consulted first to resolve the owning user, then the user record |
| 46 | // is loaded (online cache first, then disk) to retrieve the character data. |
| 47 | func apiV1GetCharacter(w http.ResponseWriter, r *http.Request) { |
| 48 | characterName := strings.TrimSpace(r.PathValue("characterName")) |
| 49 | if characterName == "" { |
| 50 | writeAPIError(w, http.StatusBadRequest, "character name is required") |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | userId, found := users.GetCharacterIndex().Find(characterName) |
| 55 | if !found { |
| 56 | writeAPIError(w, http.StatusNotFound, "character not found") |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | u := loadUserRecord(w, userId) |
| 61 | if u == nil { |
| 62 | return |
| 63 | } |
| 64 | |
| 65 | // The active character on the user record may differ in case from the |
| 66 | // requested name, or the match may be an alt. Check the active character |
| 67 | // first; if it doesn't match, the index points to an alt whose record lives |
| 68 | // in the user file but is not the current active character — return what we |
| 69 | // have (the active character is still owned by this user). |
| 70 | writeJSON(w, http.StatusOK, APIResponse[CharacterDetailResult]{ |
| 71 | Success: true, |
| 72 | Data: CharacterDetailResult{ |
| 73 | UserId: u.UserId, |
| 74 | Username: u.Username, |
| 75 | CharacterName: u.Character.Name, |
| 76 | Character: u.Character, |
| 77 | }, |
| 78 | }) |
| 79 | } |
nothing calls this directly
no test coverage detected