Allow CORS in ranking API
This commit is contained in:
parent
252d021d90
commit
5a592c505b
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
// Ranking returns the ranking information for the character via the API.
|
// Ranking returns the ranking information for the character via the API.
|
||||||
func Ranking(ctx *aero.Context) string {
|
func Ranking(ctx *aero.Context) string {
|
||||||
|
// Check character ID
|
||||||
id := ctx.Get("id")
|
id := ctx.Get("id")
|
||||||
_, err := arn.GetCharacter(id)
|
_, err := arn.GetCharacter(id)
|
||||||
|
|
||||||
@ -17,17 +18,24 @@ func Ranking(ctx *aero.Context) string {
|
|||||||
return ctx.Error(http.StatusNotFound, "Character not found", err)
|
return ctx.Error(http.StatusNotFound, "Character not found", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort characters
|
||||||
characters := arn.FilterCharacters(func(character *arn.Character) bool {
|
characters := arn.FilterCharacters(func(character *arn.Character) bool {
|
||||||
return !character.IsDraft
|
return !character.IsDraft
|
||||||
})
|
})
|
||||||
|
|
||||||
arn.SortCharactersByLikes(characters)
|
arn.SortCharactersByLikes(characters)
|
||||||
|
|
||||||
|
// Allow CORS
|
||||||
|
ctx.Response().Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
|
||||||
|
// Return ranking
|
||||||
for index, character := range characters {
|
for index, character := range characters {
|
||||||
if character.ID == id {
|
if character.ID == id {
|
||||||
return strconv.Itoa(index + 1)
|
return strconv.Itoa(index + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the ID wasn't found for some reason,
|
||||||
|
// return an empty string.
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user