mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-16 22:25:30 +08:00
6fcb9152dc
* Fix CSS for generated pdf/docx reports [SCI-7660] * Call correct asset previewable function [SCI-7660]
25 lines
1,001 B
Ruby
25 lines
1,001 B
Ruby
# frozen_string_literal: true
|
|
|
|
module ActiveStorageFileUtil
|
|
# Method expects instance of ActiveStorage::Blob as argument
|
|
def previewable_document?(blob)
|
|
previewable = Constants::PREVIEWABLE_FILE_TYPES.include?(blob.content_type)
|
|
|
|
file_extension = blob.filename.extension
|
|
content_type = blob.content_type
|
|
|
|
extensions = %w(.xlsx .docx .pptx .xls .doc .ppt)
|
|
# Mimetype sometimes recognizes Office files as zip files
|
|
# In this case we also check the extension of the given file
|
|
# Otherwise the conversion should fail if the file is being something else
|
|
previewable ||= (content_type == 'application/zip' && extensions.include?(file_extension))
|
|
|
|
# Mimetype also sometimes recognizes '.xls' and '.ppt' files as
|
|
# application/x-ole-storage (https://github.com/minad/mimemagic/issues/50)
|
|
previewable ||= (content_type == 'application/x-ole-storage' && %w(.xls .ppt).include?(file_extension))
|
|
|
|
previewable
|
|
end
|
|
|
|
module_function :previewable_document?
|
|
end
|