fix: don't add or replace parts of the sprites' URL

This commit is contained in:
Naramsim 2023-11-08 10:22:56 +01:00
parent 369d09f390
commit 3fa2b6952f

View file

@ -1507,13 +1507,6 @@ class ItemDetailSerializer(serializers.ModelSerializer):
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
@ -2689,14 +2682,6 @@ class PokemonFormDetailSerializer(serializers.ModelSerializer):
).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):
@ -2956,20 +2941,8 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
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):