preview_card_serializer.rb 606 B

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