mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-16 05:04:02 -05:00
de5305a3a5
Fix #11969
47 lines
1.1 KiB
Ruby
47 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class MediaController < ApplicationController
|
|
include Authorization
|
|
|
|
skip_before_action :store_current_location
|
|
skip_before_action :require_functional!
|
|
|
|
before_action :authenticate_user!, if: :whitelist_mode?
|
|
before_action :set_media_attachment
|
|
before_action :verify_permitted_status!
|
|
before_action :check_playable, only: :player
|
|
before_action :allow_iframing, only: :player
|
|
|
|
content_security_policy only: :player do |p|
|
|
p.frame_ancestors(false)
|
|
end
|
|
|
|
def show
|
|
redirect_to @media_attachment.file.url(:original)
|
|
end
|
|
|
|
def player
|
|
@body_classes = 'player'
|
|
end
|
|
|
|
private
|
|
|
|
def set_media_attachment
|
|
@media_attachment = MediaAttachment.attached.find_by!(shortcode: params[:id] || params[:medium_id])
|
|
end
|
|
|
|
def verify_permitted_status!
|
|
authorize @media_attachment.status, :show?
|
|
rescue Mastodon::NotPermittedError
|
|
raise ActiveRecord::RecordNotFound
|
|
end
|
|
|
|
def check_playable
|
|
not_found unless @media_attachment.larger_media_format?
|
|
end
|
|
|
|
def allow_iframing
|
|
response.headers['X-Frame-Options'] = 'ALLOWALL'
|
|
end
|
|
end
|