preview_card_serializer.rb 800 B

1234567891011121314151617181920212223242526272829
  1. # frozen_string_literal: true
  2. class REST::PreviewCardSerializer < ActiveModel::Serializer
  3. class AuthorSerializer < ActiveModel::Serializer
  4. attributes :name, :url
  5. has_one :account, serializer: REST::AccountSerializer
  6. end
  7. include RoutingHelper
  8. attributes :url, :title, :description, :language, :type,
  9. :author_name, :author_url, :provider_name,
  10. :provider_url, :html, :width, :height,
  11. :image, :image_description, :embed_url, :blurhash, :published_at
  12. has_many :authors, serializer: AuthorSerializer
  13. def url
  14. object.original_url.presence || object.url
  15. end
  16. def image
  17. object.image? ? full_asset_url(object.image.url(:original)) : nil
  18. end
  19. def html
  20. Sanitize.fragment(object.html, Sanitize::Config::MASTODON_OEMBED)
  21. end
  22. end