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.

45 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. class MediaController < ApplicationController
  3. include Authorization
  4. skip_before_action :store_current_location
  5. before_action :authenticate_user!, if: :whitelist_mode?
  6. before_action :set_media_attachment
  7. before_action :verify_permitted_status!
  8. before_action :check_playable, only: :player
  9. before_action :allow_iframing, only: :player
  10. content_security_policy only: :player do |p|
  11. p.frame_ancestors(false)
  12. end
  13. def show
  14. redirect_to @media_attachment.file.url(:original)
  15. end
  16. def player
  17. @body_classes = 'player'
  18. end
  19. private
  20. def set_media_attachment
  21. @media_attachment = MediaAttachment.attached.find_by!(shortcode: params[:id] || params[:medium_id])
  22. end
  23. def verify_permitted_status!
  24. authorize @media_attachment.status, :show?
  25. rescue Mastodon::NotPermittedError
  26. raise ActiveRecord::RecordNotFound
  27. end
  28. def check_playable
  29. not_found unless @media_attachment.larger_media_format?
  30. end
  31. def allow_iframing
  32. response.headers['X-Frame-Options'] = 'ALLOWALL'
  33. end
  34. end