use signed uuid in previews

This commit is contained in:
Pete Matsyburka
2024-02-17 22:14:28 +02:00
parent 229d78c78b
commit 323f5c0c15
10 changed files with 24 additions and 12 deletions
@@ -16,7 +16,7 @@ module Api
render json: {
schema:,
documents: documents.as_json(
methods: [:metadata],
methods: %i[metadata signed_uuid],
include: {
preview_images: { methods: %i[url metadata filename] }
}
@@ -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
Rollbar.warning("Load preview from uuid: #{params[:signed_uuid].to_s.first(10)}") if defined?(Rollbar)
ActiveStorage::Attachment.find_by(uuid: params[:signed_uuid])
end
return head :not_found unless attachment
@@ -21,9 +30,10 @@ class PreviewDocumentPageController < ActionController::API
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)
+1 -1
View File
@@ -33,7 +33,7 @@ class TemplatesController < ApplicationController
@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
@@ -12,7 +12,7 @@ class TemplatesPreviewController < ApplicationController
@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