diff --git a/app/controllers/api/templates_documents_controller.rb b/app/controllers/api/templates_documents_controller.rb index 908b899dc..f44249dad 100644 --- a/app/controllers/api/templates_documents_controller.rb +++ b/app/controllers/api/templates_documents_controller.rb @@ -16,7 +16,7 @@ def create render json: { schema:, documents: documents.as_json( - methods: [:metadata], + methods: %i[metadata signed_uuid], include: { preview_images: { methods: %i[url metadata filename] } } diff --git a/app/controllers/preview_document_page_controller.rb b/app/controllers/preview_document_page_controller.rb index 79258a5fc..9e2bfcc6c 100644 --- a/app/controllers/preview_document_page_controller.rb +++ b/app/controllers/preview_document_page_controller.rb @@ -6,7 +6,16 @@ class PreviewDocumentPageController < ActionController::API FORMAT = Templates::ProcessDocument::FORMAT def show - attachment = ActiveStorage::Attachment.find_by(uuid: params[:attachment_uuid]) + attachment_uuid = ApplicationRecord.signed_id_verifier.verified(params[:signed_uuid]) + + attachment = + if attachment_uuid + ActiveStorage::Attachment.find_by(uuid: attachment_uuid) + else + ActiveStorage::Attachment.find_by(uuid: params[:signed_uuid]) + + Rollbar.warning("Load preview from uuid: #{params[:signed_uuid].to_s.first(10)}") if defined?(Rollbar) + end return head :not_found unless attachment @@ -21,9 +30,10 @@ def show find_or_create_document_tempfile_path(attachment) end - io = Templates::ProcessDocument.generate_pdf_preview_from_file(attachment, file_path, params[:id].to_i) + preview_image = + Templates::ProcessDocument.generate_pdf_preview_from_file(attachment, file_path, params[:id].to_i) - render plain: io.tap(&:rewind).read, content_type: 'image/jpeg' + redirect_to preview_image.url, allow_other_host: true end def find_or_create_document_tempfile_path(attachment) diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 5e47d331a..794b4c6aa 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -33,7 +33,7 @@ def edit @template_data = @template.as_json.merge( documents: @template.schema_documents.as_json( - methods: [:metadata], + methods: %i[metadata signed_uuid], include: { preview_images: { methods: %i[url metadata filename] } } ) ).to_json diff --git a/app/controllers/templates_preview_controller.rb b/app/controllers/templates_preview_controller.rb index 1cac478ac..a3f4ec371 100644 --- a/app/controllers/templates_preview_controller.rb +++ b/app/controllers/templates_preview_controller.rb @@ -12,7 +12,7 @@ def show @template_data = @template.as_json.merge( documents: @template.schema_documents.as_json( - methods: [:metadata], + methods: %i[metadata signed_uuid], include: { preview_images: { methods: %i[url metadata filename] } } ) ).to_json diff --git a/app/javascript/template_builder/document.vue b/app/javascript/template_builder/document.vue index 7f8a8c216..9044f4ff3 100644 --- a/app/javascript/template_builder/document.vue +++ b/app/javascript/template_builder/document.vue @@ -102,7 +102,7 @@ export default { return this.previewImagesIndex[i] || { metadata: lazyloadMetadata, id: Math.random().toString(), - url: this.basePreviewUrl + `/preview/${this.document.uuid}/${i}.jpg` + url: this.basePreviewUrl + `/preview/${this.document.signed_uuid || this.document.uuid}/${i}.jpg` } }) }, diff --git a/app/views/submissions/show.html.erb b/app/views/submissions/show.html.erb index a96c8f10e..37dcf1e83 100644 --- a/app/views/submissions/show.html.erb +++ b/app/views/submissions/show.html.erb @@ -53,7 +53,7 @@ <% preview_images_index = document.preview_images.loaded? ? document.preview_images.index_by { |e| e.filename.base.to_i } : {} %> <% lazyload_metadata = document.preview_images.first.metadata %> <% (document.metadata.dig('pdf', 'number_of_pages') || (document.preview_images.loaded? ? preview_images_index.size : document.preview_images.size)).times do |index| %> - <% page = preview_images_index[index] || page_blob_struct.new(metadata: lazyload_metadata, url: preview_document_page_path(document.uuid, "#{index}.jpg")) %> + <% page = preview_images_index[index] || page_blob_struct.new(metadata: lazyload_metadata, url: preview_document_page_path(document.signed_uuid, "#{index}.jpg")) %>