闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
543 B

  1. # frozen_string_literal: true
  2. class ActivityPub::ImageSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :type, :media_type, :url
  5. attribute :focal_point, if: :focal_point?
  6. def type
  7. 'Image'
  8. end
  9. def url
  10. full_asset_url(object.url(:original))
  11. end
  12. def media_type
  13. object.content_type
  14. end
  15. def focal_point?
  16. object.respond_to?(:meta) && object.meta.is_a?(Hash) && object.meta['focus'].is_a?(Hash)
  17. end
  18. def focal_point
  19. [object.meta['focus']['x'], object.meta['focus']['y']]
  20. end
  21. end