mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-25 06:26:28 +08:00
Merge branch 'master' of github.com:biosistemika/scinote-web into SCI-3975-team-export
This commit is contained in:
commit
de89a97e0a
8 changed files with 35 additions and 21 deletions
|
@ -502,7 +502,7 @@ GEM
|
|||
sass-listen (4.0.0)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
rb-inotify (~> 0.9, >= 0.9.7)
|
||||
sassc (2.2.0)
|
||||
sassc (2.2.1)
|
||||
ffi (~> 1.9)
|
||||
sassc-rails (2.1.2)
|
||||
railties (>= 4.0.0)
|
||||
|
|
|
@ -36,7 +36,7 @@ class AssetsController < ApplicationController
|
|||
end
|
||||
if response_json['type'] == 'previewable'
|
||||
if ['image/jpeg', 'image/pjpeg'].include? @asset.file.content_type
|
||||
response_json['quality'] = @asset.file_image_quality || 90
|
||||
response_json['quality'] = @asset.file_image_quality || 80
|
||||
end
|
||||
response_json.merge!(
|
||||
'editable' => @asset.editable_image? && can_edit,
|
||||
|
|
|
@ -15,8 +15,6 @@ class Asset < ApplicationRecord
|
|||
# ActiveStorage configuration
|
||||
has_one_attached :file
|
||||
|
||||
# before_post_process :extract_image_quality
|
||||
|
||||
# Asset validation
|
||||
# This could cause some problems if you create empty asset and want to
|
||||
# assign it to result
|
||||
|
@ -204,18 +202,6 @@ class Asset < ApplicationRecord
|
|||
to_asset.post_process_file(to_asset.team)
|
||||
end
|
||||
|
||||
def extract_image_quality
|
||||
return unless ['image/jpeg', 'image/pjpeg'].include? content_type
|
||||
|
||||
tempfile = file.queued_for_write[:original]
|
||||
unless tempfile.nil?
|
||||
quality = Paperclip::Processor.new(tempfile).identify(" -format '%Q' #{tempfile.path}")
|
||||
self.file_image_quality = quality.to_i
|
||||
end
|
||||
rescue StandardError => e
|
||||
Rails.logger.info "There was an error extracting image quality - #{e}"
|
||||
end
|
||||
|
||||
def image?
|
||||
content_type =~ %r{^image/#{Regexp.union(Constants::WHITELISTED_IMAGE_TYPES)}}
|
||||
end
|
||||
|
|
|
@ -52,10 +52,10 @@ class UserDataDeletion
|
|||
end
|
||||
my_module.delete
|
||||
end
|
||||
|
||||
# Destroy workflow image
|
||||
if experiment.workflowimg.exists?
|
||||
experiment.workflowimg.clear(:original)
|
||||
end
|
||||
experiment.workflowimg.purge
|
||||
|
||||
experiment.activities.destroy_all
|
||||
experiment.report_elements.destroy_all
|
||||
experiment.my_module_groups.delete_all
|
||||
|
|
|
@ -157,10 +157,11 @@ module ProtocolsImporter
|
|||
|
||||
# Decode the file bytes
|
||||
file = StringIO.new(Base64.decode64(tiny_mce_img_json['bytes']))
|
||||
tiny_mce_img.image.attach(io: file,
|
||||
to_blob = ActiveStorage::Blob.create_after_upload!(io: file,
|
||||
filename: tiny_mce_img_json['fileName'],
|
||||
content_type: tiny_mce_img_json['fileType'],
|
||||
metadata: JSON.parse(tiny_mce_img_json['fileMetadata'] || '{}'))
|
||||
tiny_mce_img.image.attach(to_blob)
|
||||
if description.gsub!("data-mce-token=\"#{tiny_mce_img_json['tokenId']}\"",
|
||||
"data-mce-token=\"#{Base62.encode(tiny_mce_img.id)}\"")
|
||||
else
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'active_storage/previewer/libreoffice_previewer'
|
||||
require 'active_storage/analyzer/custom_image_analyzer'
|
||||
require 'active_storage/downloader'
|
||||
|
||||
Rails.application.config.active_storage.previewers = [ActiveStorage::Previewer::PopplerPDFPreviewer,
|
||||
ActiveStorage::Previewer::LibreofficePreviewer]
|
||||
|
||||
Rails.application.config.active_storage.analyzers.prepend(ActiveStorage::Analyzer::CustomImageAnalyzer)
|
||||
|
||||
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'
|
||||
|
|
24
lib/active_storage/analyzer/custom_image_analyzer.rb
Normal file
24
lib/active_storage/analyzer/custom_image_analyzer.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ActiveStorage
|
||||
class Analyzer::CustomImageAnalyzer < Analyzer::ImageAnalyzer
|
||||
JPEG_MIME_TYPES = ['image/jpeg', 'image/pjpeg'].freeze
|
||||
|
||||
def self.accept?(blob)
|
||||
blob.content_type.in?(JPEG_MIME_TYPES) && blob.attachments.take.record_type == 'Asset'
|
||||
end
|
||||
|
||||
def metadata
|
||||
read_image do |image|
|
||||
quality = image.identify { |b| b.format('%Q') }.to_i
|
||||
blob.attachments.take.record.update(file_image_quality: quality)
|
||||
|
||||
if rotated_image?(image)
|
||||
{ width: image.height, height: image.width }
|
||||
else
|
||||
{ width: image.width, height: image.height }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -44,7 +44,7 @@ module ActiveStorage
|
|||
end
|
||||
|
||||
def libreoffice_path
|
||||
ENV['LIBREOFFICE_PATH'] || 'libreoffice'
|
||||
ENV['LIBREOFFICE_PATH'] || 'soffice'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue