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.

37 lines
961 B

  1. # frozen_string_literal: true
  2. class MediaController < ApplicationController
  3. include Authorization
  4. skip_before_action :store_current_location
  5. before_action :set_media_attachment
  6. before_action :verify_permitted_status!
  7. content_security_policy only: :player do |p|
  8. p.frame_ancestors(false)
  9. end
  10. def show
  11. redirect_to @media_attachment.file.url(:original)
  12. end
  13. def player
  14. @body_classes = 'player'
  15. response.headers['X-Frame-Options'] = 'ALLOWALL'
  16. raise ActiveRecord::RecordNotFound unless @media_attachment.video? || @media_attachment.gifv?
  17. end
  18. private
  19. def set_media_attachment
  20. @media_attachment = MediaAttachment.attached.find_by!(shortcode: params[:id] || params[:medium_id])
  21. end
  22. def verify_permitted_status!
  23. authorize @media_attachment.status, :show?
  24. rescue Mastodon::NotPermittedError
  25. # Reraise in order to get a 404 instead of a 403 error code
  26. raise ActiveRecord::RecordNotFound
  27. end
  28. end