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.

44 lines
1009 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. before_action :check_playable, only: :player
  8. before_action :allow_iframing, only: :player
  9. content_security_policy only: :player do |p|
  10. p.frame_ancestors(false)
  11. end
  12. def show
  13. redirect_to @media_attachment.file.url(:original)
  14. end
  15. def player
  16. @body_classes = 'player'
  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. raise ActiveRecord::RecordNotFound
  26. end
  27. def check_playable
  28. not_found unless @media_attachment.larger_media_format?
  29. end
  30. def allow_iframing
  31. response.headers['X-Frame-Options'] = 'ALLOWALL'
  32. end
  33. end