Skip to content

Commit

Permalink
fix: don't add or replace parts of the sprites' URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Naramsim committed Nov 8, 2023
1 parent 369d09f commit 3fa2b69
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions pokemon_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1507,13 +1507,6 @@ def get_item_sprites(self, obj):
sprites_object = ItemSprites.objects.get(item_id=obj)
sprites_data = ItemSpritesSerializer(sprites_object, context=self.context).data
sprites_data = json.loads(sprites_data["sprites"])
host = "raw.githubusercontent.com/PokeAPI/sprites/master/"

for key in sprites_data:
if sprites_data[key]:
sprites_data[key] = (
"https://" + host + sprites_data[key].replace("/media/", "")
)

return sprites_data

Expand Down Expand Up @@ -2689,14 +2682,6 @@ def get_pokemon_form_sprites(self, obj):
).data
sprites_data = json.loads(sprites_data["sprites"])

host = "raw.githubusercontent.com/PokeAPI/sprites/master/"

for key in sprites_data:
if sprites_data[key]:
sprites_data[key] = (
"https://" + host + sprites_data[key].replace("/media/", "")
)

return sprites_data

def get_pokemon_form_types(self, obj):
Expand Down Expand Up @@ -2956,20 +2941,8 @@ def get_pokemon_sprites(self, obj):
sprites_data = PokemonSpritesSerializer(
sprites_object, context=self.context
).data
sprites_data = json.loads(sprites_data["sprites"])
host = "raw.githubusercontent.com/PokeAPI/sprites/master/"

def replace_sprite_url(d):
for key, value in d.items():
if isinstance(value, dict):
replace_sprite_url(value)
else:
if d[key]:
d[key] = "https://" + host + d[key].replace("/media/", "")

replace_sprite_url(sprites_data)

return sprites_data
return json.loads(sprites_data["sprites"])

def get_pokemon_moves(self, obj):

Expand Down

0 comments on commit 3fa2b69

Please sign in to comment.