From c3ca3801f2b8a44db09b83da2e64130eb2c41ef1 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 26 Apr 2020 23:29:08 +0200 Subject: Add separate cache directory for non-local uploads (#12821) --- config/initializers/paperclip.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'config') diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 8909678d6..43449eb4f 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -10,9 +10,25 @@ Paperclip.interpolates :filename do |attachment, style| end end +Paperclip.interpolates :path_prefix do |attachment, style| + if attachment.storage_schema_version >= 1 && attachment.instance.respond_to?(:local?) && !attachment.instance.local? + 'cache' + File::SEPARATOR + else + '' + end +end + +Paperclip.interpolates :url_prefix do |attachment, style| + if attachment.storage_schema_version >= 1 && attachment.instance.respond_to?(:local?) && !attachment.instance.local? + 'cache/' + else + '' + end +end + Paperclip::Attachment.default_options.merge!( use_timestamp: false, - path: ':class/:attachment/:id_partition/:style/:filename', + path: ':url_prefix:class/:attachment/:id_partition/:style/:filename', storage: :fog ) @@ -91,7 +107,7 @@ else Paperclip::Attachment.default_options.merge!( storage: :filesystem, use_timestamp: true, - path: File.join(ENV.fetch('PAPERCLIP_ROOT_PATH', File.join(':rails_root', 'public', 'system')), ':class', ':attachment', ':id_partition', ':style', ':filename'), - url: ENV.fetch('PAPERCLIP_ROOT_URL', '/system') + '/:class/:attachment/:id_partition/:style/:filename', + path: File.join(ENV.fetch('PAPERCLIP_ROOT_PATH', File.join(':rails_root', 'public', 'system')), ':path_prefix:class', ':attachment', ':id_partition', ':style', ':filename'), + url: ENV.fetch('PAPERCLIP_ROOT_URL', '/system') + '/:url_prefix:class/:attachment/:id_partition/:style/:filename', ) end -- cgit From acc367fd14546fda24497954774311388059b23e Mon Sep 17 00:00:00 2001 From: mayaeh Date: Mon, 27 Apr 2020 17:32:05 +0900 Subject: Fix naming issue (#13551) --- config/initializers/paperclip.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'config') diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 43449eb4f..0dd7f8cf8 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -10,7 +10,7 @@ Paperclip.interpolates :filename do |attachment, style| end end -Paperclip.interpolates :path_prefix do |attachment, style| +Paperclip.interpolates :prefix_path do |attachment, style| if attachment.storage_schema_version >= 1 && attachment.instance.respond_to?(:local?) && !attachment.instance.local? 'cache' + File::SEPARATOR else @@ -18,7 +18,7 @@ Paperclip.interpolates :path_prefix do |attachment, style| end end -Paperclip.interpolates :url_prefix do |attachment, style| +Paperclip.interpolates :prefix_url do |attachment, style| if attachment.storage_schema_version >= 1 && attachment.instance.respond_to?(:local?) && !attachment.instance.local? 'cache/' else @@ -28,7 +28,7 @@ end Paperclip::Attachment.default_options.merge!( use_timestamp: false, - path: ':url_prefix:class/:attachment/:id_partition/:style/:filename', + path: ':prefix_url:class/:attachment/:id_partition/:style/:filename', storage: :fog ) @@ -107,7 +107,7 @@ else Paperclip::Attachment.default_options.merge!( storage: :filesystem, use_timestamp: true, - path: File.join(ENV.fetch('PAPERCLIP_ROOT_PATH', File.join(':rails_root', 'public', 'system')), ':path_prefix:class', ':attachment', ':id_partition', ':style', ':filename'), - url: ENV.fetch('PAPERCLIP_ROOT_URL', '/system') + '/:url_prefix:class/:attachment/:id_partition/:style/:filename', + path: File.join(ENV.fetch('PAPERCLIP_ROOT_PATH', File.join(':rails_root', 'public', 'system')), ':prefix_path:class', ':attachment', ':id_partition', ':style', ':filename'), + url: ENV.fetch('PAPERCLIP_ROOT_URL', '/system') + '/:prefix_url:class/:attachment/:id_partition/:style/:filename', ) end -- cgit