logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

media_attachment_serializer.rb (755B)


  1. # frozen_string_literal: true
  2. class REST::MediaAttachmentSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :id, :type, :url, :preview_url,
  5. :remote_url, :text_url, :meta,
  6. :description
  7. def id
  8. object.id.to_s
  9. end
  10. def url
  11. if object.needs_redownload?
  12. media_proxy_url(object.id, :original)
  13. else
  14. full_asset_url(object.file.url(:original))
  15. end
  16. end
  17. def remote_url
  18. object.remote_url.presence
  19. end
  20. def preview_url
  21. if object.needs_redownload?
  22. media_proxy_url(object.id, :small)
  23. else
  24. full_asset_url(object.file.url(:small))
  25. end
  26. end
  27. def text_url
  28. object.local? ? medium_url(object) : nil
  29. end
  30. def meta
  31. object.file.meta
  32. end
  33. end