image_serializer.rb 543 B

12345678910111213141516171819202122232425262728
  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