image_serializer.rb 578 B

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