From ee9ee6ee324b1b68b6ff9acd68e5f09f6216ae9e Mon Sep 17 00:00:00 2001 From: Pete Matsyburka Date: Sat, 20 Jul 2024 21:17:47 +0300 Subject: [PATCH] adjust attachment create --- app/controllers/templates_uploads_controller.rb | 2 +- lib/templates/create_attachments.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/templates_uploads_controller.rb b/app/controllers/templates_uploads_controller.rb index fe9fe541..7d106675 100644 --- a/app/controllers/templates_uploads_controller.rb +++ b/app/controllers/templates_uploads_controller.rb @@ -58,7 +58,7 @@ class TemplatesUploadsController < ApplicationController file = ActionDispatch::Http::UploadedFile.new( tempfile:, filename: File.basename( - URI.decode_www_form_component(params[:filename].presence || params[:url]) + URI.decode_www_form_component(params[:filename].presence || params[:url]), '.*' ), type: Marcel::MimeType.for(tempfile) ) diff --git a/lib/templates/create_attachments.rb b/lib/templates/create_attachments.rb index 7418c1dd..22d84e2f 100644 --- a/lib/templates/create_attachments.rb +++ b/lib/templates/create_attachments.rb @@ -11,11 +11,7 @@ module Templates def call(template, params, extract_fields: false) Array.wrap(params[:files].presence || params[:file]).map do |file| - if file.content_type.exclude?('image') && file.content_type != PDF_CONTENT_TYPE - next handle_file_types(template, file, params) - end - - handle_pdf_or_image(template, file, file.read, params, extract_fields:) + handle_file_types(template, file, params, extract_fields:) end end @@ -57,7 +53,11 @@ module Templates raise PdfEncrypted end - def handle_file_types(_template, file, _params) + def handle_file_types(template, file, params, extract_fields:) + if file.content_type.include?('image') || file.content_type == PDF_CONTENT_TYPE + return handle_pdf_or_image(template, file, file.read, params, extract_fields:) + end + raise InvalidFileType, file.content_type end end