闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
848 B

  1. # frozen_string_literal: true
  2. class Api::V1::MediaController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :write }
  4. before_action :require_user!
  5. include ObfuscateFilename
  6. obfuscate_filename :file
  7. respond_to :json
  8. def create
  9. @media = current_account.media_attachments.create!(file: media_params[:file])
  10. render json: @media, serializer: REST::MediaAttachmentSerializer
  11. rescue Paperclip::Errors::NotIdentifiedByImageMagickError
  12. render json: file_type_error, status: 422
  13. rescue Paperclip::Error
  14. render json: processing_error, status: 500
  15. end
  16. private
  17. def media_params
  18. params.permit(:file)
  19. end
  20. def file_type_error
  21. { error: 'File type of uploaded media could not be verified' }
  22. end
  23. def processing_error
  24. { error: 'Error processing thumbnail for uploaded media' }
  25. end
  26. end