diff --git a/app/controllers/preview_document_page_controller.rb b/app/controllers/preview_document_page_controller.rb deleted file mode 100644 index 5e59e74a2..000000000 --- a/app/controllers/preview_document_page_controller.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -class PreviewDocumentPageController < ActionController::API - include ActiveStorage::SetCurrent - - FORMAT = Templates::ProcessDocument::FORMAT - - def show - attachment_uuid = ApplicationRecord.signed_id_verifier.verified(params[:signed_uuid], purpose: :attachment) - - attachment = ActiveStorage::Attachment.find_by(uuid: attachment_uuid) if attachment_uuid - - return head :not_found unless attachment - - @template = attachment.record - - preview_image = attachment.preview_images.joins(:blob) - .find_by(blob: { filename: ["#{params[:id]}.png", "#{params[:id]}.jpg"] }) - - return redirect_to preview_image.url, allow_other_host: true if preview_image - - file_path = - if attachment.service.name == :disk - ActiveStorage::Blob.service.path_for(attachment.key) - else - find_or_create_document_tempfile_path(attachment) - end - - preview_image = - Templates::ProcessDocument.generate_pdf_preview_from_file(attachment, file_path, params[:id].to_i) - - redirect_to preview_image.url, allow_other_host: true - end - - def find_or_create_document_tempfile_path(attachment) - file_path = "#{Dir.tmpdir}/#{attachment.uuid}" - - File.open(file_path, File::RDWR | File::CREAT, 0o644) do |f| - f.flock(File::LOCK_EX) - - # rubocop:disable Style/ZeroLengthPredicate - if f.size.zero? - f.binmode - - f.write(attachment.download) - end - # rubocop:enable Style/ZeroLengthPredicate - end - - file_path - end -end diff --git a/app/javascript/template_builder/builder.vue b/app/javascript/template_builder/builder.vue index f576ffc84..17e6a248b 100644 --- a/app/javascript/template_builder/builder.vue +++ b/app/javascript/template_builder/builder.vue @@ -203,7 +203,6 @@ :draw-field="drawField" :draw-field-type="drawFieldType" :editable="editable" - :base-url="baseUrl" @draw="[onDraw($event), withSelectedFieldType ? '' : drawFieldType = '', showDrawField = false]" @drop-field="onDropfield" @remove-area="removeArea" diff --git a/app/javascript/template_builder/document.vue b/app/javascript/template_builder/document.vue index 2c7592c75..099c95122 100644 --- a/app/javascript/template_builder/document.vue +++ b/app/javascript/template_builder/document.vue @@ -95,11 +95,6 @@ export default { required: false, default: null }, - baseUrl: { - type: String, - required: false, - default: '' - }, isDrag: { type: Boolean, required: false, @@ -113,26 +108,13 @@ export default { } }, computed: { - basePreviewUrl () { - if (this.baseUrl) { - return new URL(this.baseUrl).origin - } else { - return '' - } - }, numberOfPages () { return this.document.metadata?.pdf?.number_of_pages || this.document.preview_images.length }, sortedPreviewImages () { - const lazyloadMetadata = this.document.preview_images[this.document.preview_images.length - 1].metadata - - return [...Array(this.numberOfPages).keys()].map((i) => { - return this.previewImagesIndex[i] || { - metadata: lazyloadMetadata, - id: Math.random().toString(), - url: this.basePreviewUrl + `/preview/${this.document.signed_uuid || this.document.uuid}/${i}.jpg` - } - }) + return [...Array(this.numberOfPages).keys()] + .map((i) => this.previewImagesIndex[i] ? { ...this.previewImagesIndex[i], _pageIndex: i } : null) + .filter(Boolean) }, previewImagesIndex () { return this.document.preview_images.reduce((acc, e) => { diff --git a/app/javascript/template_builder/dropzone.vue b/app/javascript/template_builder/dropzone.vue index 2485bd23a..453491fb8 100644 --- a/app/javascript/template_builder/dropzone.vue +++ b/app/javascript/template_builder/dropzone.vue @@ -35,11 +35,17 @@ {{ message }}