handle unsupported file types
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user