mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-07 06:56:18 +08:00
Add CustomDisk Service for ActiveStorage
This commit is contained in:
parent
9c88327a16
commit
81d66ceedd
7 changed files with 21 additions and 25 deletions
|
|
@ -243,12 +243,6 @@ class Asset < ApplicationRecord
|
||||||
to_asset.post_process_file(to_asset.team)
|
to_asset.post_process_file(to_asset.team)
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_service_url
|
|
||||||
ActiveStorage::Current.set(host: Rails.application.secrets.mail_server_url) do
|
|
||||||
file.service_url
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def extract_image_quality
|
def extract_image_quality
|
||||||
return unless ['image/jpeg', 'image/pjpeg'].include? content_type
|
return unless ['image/jpeg', 'image/pjpeg'].include? content_type
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,6 @@ class TempFile < ApplicationRecord
|
||||||
|
|
||||||
has_one_attached :file
|
has_one_attached :file
|
||||||
|
|
||||||
def file_service_url
|
|
||||||
ActiveStorage::Current.set(host: Rails.application.secrets.mail_server_url) do
|
|
||||||
file.service_url
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def destroy_obsolete(temp_file_id)
|
def destroy_obsolete(temp_file_id)
|
||||||
temp_file = find_by_id(temp_file_id)
|
temp_file = find_by_id(temp_file_id)
|
||||||
|
|
|
||||||
|
|
@ -102,12 +102,6 @@ class TinyMceAsset < ApplicationRecord
|
||||||
image.variant(resize_to_limit: Constants::LARGE_PIC_FORMAT)
|
image.variant(resize_to_limit: Constants::LARGE_PIC_FORMAT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_service_url
|
|
||||||
ActiveStorage::Current.set(host: Rails.application.secrets.mail_server_url) do
|
|
||||||
image.service_url
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.delete_unsaved_image(id)
|
def self.delete_unsaved_image(id)
|
||||||
asset = find_by(id: id)
|
asset = find_by(id: id)
|
||||||
asset.destroy if asset && !asset.saved
|
asset.destroy if asset && !asset.saved
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ module Reports::Docx::PrivateMethods
|
||||||
image = TinyMceAsset.find_by(id: Base62.decode(elem.attributes['data-mce-token'].value))
|
image = TinyMceAsset.find_by(id: Base62.decode(elem.attributes['data-mce-token'].value))
|
||||||
next unless image
|
next unless image
|
||||||
|
|
||||||
image_path = image_path(image)
|
image_path = image_path(image.image)
|
||||||
dimension = FastImage.size(image_path)
|
dimension = FastImage.size(image_path)
|
||||||
style = image_styling(elem, dimension)
|
style = image_styling(elem, dimension)
|
||||||
|
|
||||||
|
|
@ -204,7 +204,7 @@ module Reports::Docx::PrivateMethods
|
||||||
def asset_image_preparing(asset)
|
def asset_image_preparing(asset)
|
||||||
return unless asset
|
return unless asset
|
||||||
|
|
||||||
image_path = image_path(asset)
|
image_path = image_path(asset.file)
|
||||||
|
|
||||||
dimension = FastImage.size(image_path)
|
dimension = FastImage.size(image_path)
|
||||||
x = dimension[0]
|
x = dimension[0]
|
||||||
|
|
@ -292,8 +292,8 @@ module Reports::Docx::PrivateMethods
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_path(asset)
|
def image_path(attachment)
|
||||||
asset.file_service_url
|
attachment.service_url
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_color_hsp(color)
|
def calculate_color_hsp(color)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class SpreadsheetParser
|
||||||
file_path = file.path
|
file_path = file.path
|
||||||
else
|
else
|
||||||
filename = file.filename.to_s
|
filename = file.filename.to_s
|
||||||
file_path = file.file_service_url
|
file_path = file.service_url
|
||||||
end
|
end
|
||||||
|
|
||||||
case File.extname(filename)
|
case File.extname(filename)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
test:
|
test:
|
||||||
service: Disk
|
service: CustomDisk
|
||||||
root: <%= Rails.root.join("tmp/storage") %>
|
root: <%= Rails.root.join("tmp/storage") %>
|
||||||
|
|
||||||
local:
|
local:
|
||||||
service: Disk
|
service: CustomDisk
|
||||||
root: <%= Rails.root.join("storage") %>
|
root: <%= Rails.root.join("storage") %>
|
||||||
|
|
||||||
amazon:
|
amazon:
|
||||||
|
|
|
||||||
14
lib/active_storage/service/custom_disk_service.rb
Normal file
14
lib/active_storage/service/custom_disk_service.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'active_storage/service/disk_service'
|
||||||
|
|
||||||
|
module ActiveStorage
|
||||||
|
class Service::CustomDiskService < Service::DiskService
|
||||||
|
def current_host
|
||||||
|
host = ActiveStorage::Current.host
|
||||||
|
host ||= Rails.application.secrets.mail_server_url
|
||||||
|
host = "http://#{host}" unless host.match?(/^http/)
|
||||||
|
host
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Reference in a new issue