mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-27 23:45:52 +08:00
Merge pull request #2072 from okriuchykhin/ok_SCI_3888
Add override for ActiveStorage downloader to handle missing file checksums [SCI-3888]
This commit is contained in:
commit
25c91c2724
2 changed files with 16 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'active_storage/previewer/libreoffice_previewer'
|
||||
require 'active_storage/downloader'
|
||||
|
||||
Rails.application.config.active_storage.previewers = [ActiveStorage::Previewer::PopplerPDFPreviewer,
|
||||
ActiveStorage::Previewer::LibreofficePreviewer]
|
||||
|
@ -8,3 +9,17 @@ Rails.application.config.active_storage.previewers = [ActiveStorage::Previewer::
|
|||
Rails.application.config.active_storage.variable_content_types << 'image/svg+xml'
|
||||
|
||||
Rails.application.config.active_storage.variant_processor = :vips if ENV['ACTIVESTORAGE_ENABLE_VIPS'] == 'true'
|
||||
|
||||
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
|
||||
|
|
|
@ -26,6 +26,7 @@ class ConvertToActiveStorage < ActiveRecord::Migration[5.2]
|
|||
transaction do
|
||||
models.each do |model|
|
||||
next unless ActiveRecord::Base.connection.table_exists?(model.table_name)
|
||||
next if model.name == 'TeamZipExport'
|
||||
|
||||
attachments = model.column_names.map do |c|
|
||||
$1 if c =~ /(.+)_file_name$/
|
||||
|
|
Loading…
Add table
Reference in a new issue