From 78e9e66cb035bebb02f4ba3c46efdaf35de2b333 Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Sun, 18 Feb 2024 12:58:36 +0200 Subject: [PATCH] use uuid blobs controller --- ...e_storage_blobs_proxy_legacy_controller.rb | 35 +++++++++++++++++++ app/views/submissions/show.html.erb | 2 +- config/application.rb | 2 ++ config/initializers/devise.rb | 2 +- config/routes.rb | 12 ++++++- 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 app/controllers/api/active_storage_blobs_proxy_legacy_controller.rb diff --git a/app/controllers/api/active_storage_blobs_proxy_legacy_controller.rb b/app/controllers/api/active_storage_blobs_proxy_legacy_controller.rb new file mode 100644 index 00000000..9be8a931 --- /dev/null +++ b/app/controllers/api/active_storage_blobs_proxy_legacy_controller.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Api + class ActiveStorageBlobsProxyLegacyController < ApiBaseController + include ActiveStorage::Streaming + + skip_before_action :authenticate_user! + skip_authorization_check + + def show + Rollbar.info('Blob legacy') if defined?(Rollbar) + + return render json: { error: 'Not authenticated' }, status: :unauthorized unless current_user + + blob = ActiveStorage::Blob.find_signed!(params[:signed_blob_id] || params[:signed_id]) + + if blob.attachments.none? { |a| a.record.account.id == current_user.account_id } + Rollbar.error("Blob account not found: #{blob.id}") if defined?(Rollbar) + + return head :not_found + end + + if request.headers['Range'].present? + send_blob_byte_range_data blob, request.headers['Range'] + else + http_cache_forever public: true do + response.headers['Accept-Ranges'] = 'bytes' + response.headers['Content-Length'] = blob.byte_size.to_s + + send_blob_stream blob, disposition: params[:disposition] + end + end + end + end +end diff --git a/app/views/submissions/show.html.erb b/app/views/submissions/show.html.erb index 16be0f4a..5c6b3e2e 100644 --- a/app/views/submissions/show.html.erb +++ b/app/views/submissions/show.html.erb @@ -6,7 +6,7 @@
<% if @submission.audit_trail.present? %> - + <%= svg_icon('external_link', class: 'w-6 h-6') %>