handle unsupported file types

This commit is contained in:
Alex Turchyn
2023-09-05 20:33:40 +03:00
parent e7594d81b6
commit 2ad5f8a316
7 changed files with 48 additions and 7 deletions
+11 -2
View File
@@ -3,15 +3,20 @@
module Templates
module CreateAttachments
PDF_CONTENT_TYPE = 'application/pdf'
InvalidFileType = Class.new(StandardError)
module_function
def call(template, params)
find_or_create_blobs(params).map do |blob|
document = template.documents.create!(blob:)
document_data = blob.download
if !blob.image? && blob.content_type != PDF_CONTENT_TYPE
blob, document_data = handle_file_types(blob, document_data)
end
document = template.documents.create!(blob:)
if blob.content_type == PDF_CONTENT_TYPE && blob.metadata['pdf'].nil?
blob.metadata['pdf'] = { 'annotations' => Templates::BuildAnnotations.call(document_data) }
end
@@ -43,5 +48,9 @@ module Templates
)
end
end
def handle_file_types(_document_data, blob)
raise InvalidFileType, blob.content_type
end
end
end