diff --git a/api/api/serializers/image_serializers.py b/api/api/serializers/image_serializers.py index 78e5c668a29..4f0af390d26 100644 --- a/api/api/serializers/image_serializers.py +++ b/api/api/serializers/image_serializers.py @@ -1,3 +1,5 @@ +from typing import Literal + from rest_framework import serializers from api.constants.field_order import field_position_map @@ -133,14 +135,13 @@ class OembedSerializer(BaseModelSerializer): spec: https://oembed.com. """ - version = serializers.ReadOnlyField( + version = serializers.SerializerMethodField( help_text="The oEmbed version number, always set to 1.0.", - default="1.0", ) - type = serializers.ReadOnlyField( + type = serializers.SerializerMethodField( help_text="The resource type, always set to 'photo' for images.", - default="photo", ) + width = serializers.SerializerMethodField( help_text="The width of the image in pixels." ) @@ -156,6 +157,14 @@ class OembedSerializer(BaseModelSerializer): source="creator_url", ) + @staticmethod + def get_type(*_) -> Literal["photo"]: + return "photo" + + @staticmethod + def get_version(*_) -> Literal["1.0"]: + return "1.0" + class Meta: model = Image fields = [ diff --git a/api/api/serializers/provider_serializers.py b/api/api/serializers/provider_serializers.py index 8f2126a8699..c4ed2ae97d1 100644 --- a/api/api/serializers/provider_serializers.py +++ b/api/api/serializers/provider_serializers.py @@ -21,14 +21,17 @@ class ProviderSerializer(serializers.ModelSerializer): source="domain_name", help_text="The URL of the source, e.g. https://www.flickr.com", ) - logo_url = serializers.ReadOnlyField( - default=None, + logo_url = serializers.SerializerMethodField( help_text="The URL to a logo for the source.", ) media_count = serializers.SerializerMethodField( help_text="The number of media items indexed from the source.", ) + @staticmethod + def get_logo_url(*_) -> str | None: + return None + class Meta: model = ContentProvider fields = [