media_controller.rb 754 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. class Api::V2::MediaController < Api::V1::MediaController
  3. def create
  4. @media_attachment = current_account.media_attachments.create!(media_and_delay_params)
  5. render json: @media_attachment, serializer: REST::MediaAttachmentSerializer, status: status_from_media_processing
  6. rescue Paperclip::Errors::NotIdentifiedByImageMagickError
  7. render json: file_type_error, status: 422
  8. rescue Paperclip::Error => e
  9. Rails.logger.error "#{e.class}: #{e.message}"
  10. render json: processing_error, status: 500
  11. end
  12. private
  13. def media_and_delay_params
  14. { delay_processing: true }.merge(media_attachment_params)
  15. end
  16. def status_from_media_processing
  17. @media_attachment.not_processed? ? 202 : 200
  18. end
  19. end