2019-07-10 20:37:23 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-16 16:26:13 +08:00
|
|
|
require 'active_storage/previewer/libreoffice_previewer'
|
2019-10-08 16:42:55 +08:00
|
|
|
require 'active_storage/analyzer/custom_image_analyzer'
|
2019-09-18 21:34:49 +08:00
|
|
|
require 'active_storage/downloader'
|
2019-09-16 16:26:13 +08:00
|
|
|
|
2019-07-10 20:37:23 +08:00
|
|
|
Rails.application.config.active_storage.previewers = [ActiveStorage::Previewer::PopplerPDFPreviewer,
|
|
|
|
ActiveStorage::Previewer::LibreofficePreviewer]
|
2019-09-12 23:21:48 +08:00
|
|
|
|
2019-10-08 16:42:55 +08:00
|
|
|
Rails.application.config.active_storage.analyzers.prepend(ActiveStorage::Analyzer::CustomImageAnalyzer)
|
|
|
|
|
2019-09-12 23:21:48 +08:00
|
|
|
Rails.application.config.active_storage.variable_content_types << 'image/svg+xml'
|
|
|
|
|
2019-09-18 15:49:02 +08:00
|
|
|
Rails.application.config.active_storage.variant_processor = :vips if ENV['ACTIVESTORAGE_ENABLE_VIPS'] == 'true'
|
2019-09-18 21:34:49 +08:00
|
|
|
|
|
|
|
ActiveStorage::Downloader.class_eval do
|
|
|
|
def open(key, checksum:, name: 'ActiveStorage-', tmpdir: nil)
|
|
|
|
open_tempfile(name, tmpdir) do |file|
|
|
|
|
download key, file
|
|
|
|
if checksum == 'dummy' || checksum.nil?
|
|
|
|
ActiveStorage::Blob.find_by(key: key).update(checksum: Digest::MD5.file(file).base64digest)
|
|
|
|
else
|
|
|
|
verify_integrity_of file, checksum: checksum
|
|
|
|
end
|
|
|
|
yield file
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|