logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

media_proxy_controller.rb (926B)


  1. # frozen_string_literal: true
  2. class MediaProxyController < ApplicationController
  3. include RoutingHelper
  4. def show
  5. RedisLock.acquire(lock_options) do |lock|
  6. if lock.acquired?
  7. @media_attachment = MediaAttachment.remote.find(params[:id])
  8. redownload! if @media_attachment.needs_redownload? && !reject_media?
  9. end
  10. end
  11. redirect_to full_asset_url(@media_attachment.file.url(version))
  12. end
  13. private
  14. def redownload!
  15. @media_attachment.file_remote_url = @media_attachment.remote_url
  16. @media_attachment.created_at = Time.now.utc
  17. @media_attachment.save!
  18. end
  19. def version
  20. if request.path.ends_with?('/small')
  21. :small
  22. else
  23. :original
  24. end
  25. end
  26. def lock_options
  27. { redis: Redis.current, key: "media_download:#{params[:id]}" }
  28. end
  29. def reject_media?
  30. DomainBlock.find_by(domain: @media_attachment.account.domain)&.reject_media?
  31. end
  32. end