mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 09:21:11 +00:00
Merge 3bfd4b4a92
into 14cb5ff881
This commit is contained in:
commit
c6836bdd23
|
@ -10,6 +10,7 @@ class MediaProxyController < ApplicationController
|
|||
|
||||
before_action :authenticate_user!, if: :limited_federation_mode?
|
||||
before_action :set_media_attachment
|
||||
before_action :redownload_media, if: :redownload_required?
|
||||
|
||||
rescue_from ActiveRecord::RecordInvalid, with: :not_found
|
||||
rescue_from Mastodon::UnexpectedResponseError, with: :not_found
|
||||
|
@ -17,13 +18,6 @@ class MediaProxyController < ApplicationController
|
|||
rescue_from(*Mastodon::HTTP_CONNECTION_ERRORS, with: :internal_server_error)
|
||||
|
||||
def show
|
||||
if @media_attachment.needs_redownload? && !reject_media?
|
||||
with_redis_lock("media_download:#{params[:id]}") do
|
||||
@media_attachment.reload # Reload once we have acquired a lock, in case the file was downloaded in the meantime
|
||||
redownload! if @media_attachment.needs_redownload?
|
||||
end
|
||||
end
|
||||
|
||||
if requires_file_streaming?
|
||||
send_file(media_attachment_file.path, type: media_attachment_file.instance_read(:content_type), disposition: 'inline')
|
||||
else
|
||||
|
@ -33,6 +27,18 @@ class MediaProxyController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def redownload_required?
|
||||
@media_attachment.needs_redownload? && !reject_media?
|
||||
end
|
||||
|
||||
def redownload_media
|
||||
with_redis_lock("media_download:#{params[:id]}") do
|
||||
# Reload within lock in case the file was downloaded in the meantime
|
||||
@media_attachment.reload
|
||||
redownload! if @media_attachment.needs_redownload?
|
||||
end
|
||||
end
|
||||
|
||||
def set_media_attachment
|
||||
@media_attachment = MediaAttachment.attached.find(params[:id])
|
||||
authorize @media_attachment, :download?
|
||||
|
|
Loading…
Reference in New Issue
Block a user