Skip to content

Commit

Permalink
fix: hasPaid route and nameHistory deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
net32 committed May 26, 2024
1 parent 4a0cf98 commit 622cceb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func HasPaid(userName string) (string, MojangResponse) {
if data.Code == 200 {
result = "true"
}
if data.Code == 204 {
if data.Code == 404 {
result = "false"
}
return result, data
Expand Down
2 changes: 1 addition & 1 deletion server/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func HasCache(cacheKey string) CacheResponse {

func SaveCache(cacheKey string, response MojangResponse) CacheResponse {
saved := false
if response.Code < 500 {
if response.Code < 405 {
data, err := json.Marshal(response)
if err != nil {
log.Println(err, "SaveCache:", cacheKey, response)
Expand Down
1 change: 1 addition & 0 deletions server/mojang.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func UuidToName(uuid string, action string) MojangResponse {
return mojangGet(URL)
}

// This endpoint has been deprecated by Mojang and was removed on 13 September 2022 at 9:25 AM CET to "improve player safety and data privacy"
func UuidToNameHistory(uuid string) MojangResponse {
return UuidToName(uuid, "names")
}
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func InitServer() {
}
writeJsonResponse(c, UsernamesToUUIDs(b))
})
// This endpoint has been deprecated by Mojang and was removed on 13 September 2022 at 9:25 AM CET to "improve player safety and data privacy"
r.GET("/user/profiles/:uuid/*action", func(c *gin.Context) {
uuid := c.Params.ByName("uuid")
writeJsonResponse(c, UuidToNameHistory(uuid))
Expand Down
24 changes: 21 additions & 3 deletions test/mojang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func TestFetchProfileByName(t *testing.T) {
}

func TestUuidToNameHistory(t *testing.T) {
t.Log("Testing UuidToNameHistory expected", HTTP_200_OK)
t.Log("Testing UuidToNameHistory expected", HTTP_404_Not_Found)
response := server.UuidToNameHistory("c5870df7-44e9-495f-928a-0e3e8703a03e")
if response.Code != HTTP_200_OK {
t.Errorf("Expected %d return %d", HTTP_200_OK, response.Code)
if response.Code != HTTP_404_Not_Found {
t.Errorf("Expected %d return %d", HTTP_404_Not_Found, response.Code)
}
t.Log("Response:", response)
}
Expand All @@ -47,3 +47,21 @@ func TestBlockedServers(t *testing.T) {
}
t.Log("Response:", response.Code, "total", len(response.Json))
}

func TestHasPaidTrue(t *testing.T) {
t.Log("Testing HasPaid expected", "true")
response, data := server.HasPaid("net32")
if response != "true" {
t.Errorf("Expected %s return %s", "true", response)
}
t.Log("Response:", response, "data", data)
}

func TestHasPaidFalse(t *testing.T) {
t.Log("Testing HasPaid expected", "false")
response, data := server.HasPaid("net32_random_404_name")
if response != "false" {
t.Errorf("Expected %s return %s", "false", response)
}
t.Log("Response:", response, "data", data)
}

0 comments on commit 622cceb

Please sign in to comment.