闭社主体 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.

33 lines
779 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. rescue Paperclip::Errors::NotIdentifiedByImageMagickError
  11. render json: file_type_error, status: 422
  12. rescue Paperclip::Error
  13. render json: processing_error, status: 500
  14. end
  15. private
  16. def media_params
  17. params.permit(:file)
  18. end
  19. def file_type_error
  20. { error: 'File type of uploaded media could not be verified' }
  21. end
  22. def processing_error
  23. { error: 'Error processing thumbnail for uploaded media' }
  24. end
  25. end