media_controller.rb 544 B

123456789101112131415161718192021222324
  1. # frozen_string_literal: true
  2. class MediaController < ApplicationController
  3. include Authorization
  4. before_action :verify_permitted_status
  5. def show
  6. redirect_to media_attachment.file.url(:original)
  7. end
  8. private
  9. def media_attachment
  10. MediaAttachment.attached.find_by!(shortcode: params[:id])
  11. end
  12. def verify_permitted_status
  13. authorize media_attachment.status, :show?
  14. rescue Mastodon::NotPermittedError
  15. # Reraise in order to get a 404 instead of a 403 error code
  16. raise ActiveRecord::RecordNotFound
  17. end
  18. end