|
|
|
|
@ -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)
|
|
|
|
|
|