mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-26 15:31:52 +00:00
258dce1256
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.1) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.1) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.1) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
48 lines
1.2 KiB
Ruby
48 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class MediaProxyController < ApplicationController
|
|
include RoutingHelper
|
|
include Authorization
|
|
include Redisable
|
|
include Lockable
|
|
|
|
skip_before_action :require_functional!
|
|
|
|
before_action :authenticate_user!, if: :limited_federation_mode?
|
|
|
|
rescue_from ActiveRecord::RecordInvalid, with: :not_found
|
|
rescue_from Mastodon::UnexpectedResponseError, with: :not_found
|
|
rescue_from Mastodon::NotPermittedError, with: :not_found
|
|
rescue_from(*Mastodon::HTTP_CONNECTION_ERRORS, with: :internal_server_error)
|
|
|
|
def show
|
|
with_redis_lock("media_download:#{params[:id]}") do
|
|
@media_attachment = MediaAttachment.remote.attached.find(params[:id])
|
|
authorize @media_attachment.status, :show?
|
|
redownload! if @media_attachment.needs_redownload? && !reject_media?
|
|
end
|
|
|
|
redirect_to full_asset_url(@media_attachment.file.url(version)), allow_other_host: true
|
|
end
|
|
|
|
private
|
|
|
|
def redownload!
|
|
@media_attachment.download_file!
|
|
@media_attachment.created_at = Time.now.utc
|
|
@media_attachment.save!
|
|
end
|
|
|
|
def version
|
|
if request.path.end_with?('/small')
|
|
:small
|
|
else
|
|
:original
|
|
end
|
|
end
|
|
|
|
def reject_media?
|
|
DomainBlock.reject_media?(@media_attachment.account.domain)
|
|
end
|
|
end
|