Fix file previews in project exports [SCI-9619] (#6548)

This commit is contained in:
Alex Kriuchykhin 2023-10-30 17:28:53 +01:00 committed by GitHub
parent e73543dd90
commit d3ba70c2bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -187,11 +187,19 @@ class TeamZipExportJob < ZipExportJob
def prepare_preview(asset)
if asset.previewable? && !asset.list?
preview = asset.inline? ? asset.large_preview : asset.medium_preview
return unless preview.image.attached?
begin
file_name = preview.image.filename.to_s
file_data = preview.image.download
if preview.is_a?(ActiveStorage::Preview)
return unless preview.image.attached?
file_name = preview.image.filename.to_s
file_data = preview.image.download
else
return unless preview.processed?
file_name = preview.filename.to_s
file_data = preview.download
end
rescue ActiveStorage::FileNotFoundError => e
Rails.logger.error(e.message)
Rails.logger.error(e.backtrace.join("\n"))

View file

@ -473,7 +473,7 @@ class Asset < ApplicationRecord
def previewable_image?
preview_image.attached? ||
file.blob&.content_type =~ %r{^image/#{Regexp.union(Constants::WHITELISTED_IMAGE_TYPES)}}
file.blob&.content_type&.match?(%r{^image/#{Regexp.union(Constants::WHITELISTED_IMAGE_TYPES)}})
end
def step_or_result_or_repository_asset_value