media_attachment_serializer.rb 808 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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, :blurhash
  7. def id
  8. object.id.to_s
  9. end
  10. def url
  11. if object.not_processed?
  12. nil
  13. elsif object.needs_redownload?
  14. media_proxy_url(object.id, :original)
  15. else
  16. full_asset_url(object.file.url(:original))
  17. end
  18. end
  19. def remote_url
  20. object.remote_url.presence
  21. end
  22. def preview_url
  23. if object.needs_redownload?
  24. media_proxy_url(object.id, :small)
  25. else
  26. full_asset_url(object.file.url(:small))
  27. end
  28. end
  29. def text_url
  30. object.local? ? medium_url(object) : nil
  31. end
  32. def meta
  33. object.file.meta
  34. end
  35. end