logo

mastofe

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

media_controller.rb (1066B)


  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!(media_params)
  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. def update
  17. @media = current_account.media_attachments.where(status_id: nil).find(params[:id])
  18. @media.update!(media_params)
  19. render json: @media, serializer: REST::MediaAttachmentSerializer
  20. end
  21. private
  22. def media_params
  23. params.permit(:file, :description, :focus)
  24. end
  25. def file_type_error
  26. { error: 'File type of uploaded media could not be verified' }
  27. end
  28. def processing_error
  29. { error: 'Error processing thumbnail for uploaded media' }
  30. end
  31. end