mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add both safe and unsafe Discourse.store.download methods (#21498)
* DEV: Add both safe and unsafe Discourse.store.download methods * DEV: Update call sites that can use the safe store download method
This commit is contained in:
@@ -55,13 +55,8 @@ class OptimizedImage < ActiveRecord::Base
|
||||
|
||||
if original_path.blank?
|
||||
# download is protected with a DistributedMutex
|
||||
external_copy =
|
||||
begin
|
||||
Discourse.store.download(upload)
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
original_path = external_copy.try(:path)
|
||||
external_copy = Discourse.store.download_safe(upload)
|
||||
original_path = external_copy&.path
|
||||
end
|
||||
|
||||
lock(upload.id, width, height) do
|
||||
|
||||
@@ -189,13 +189,8 @@ class ThemeField < ActiveRecord::Base
|
||||
end
|
||||
|
||||
if Discourse.store.external?
|
||||
external_copy =
|
||||
begin
|
||||
Discourse.store.download(upload)
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
path = external_copy.try(:path)
|
||||
external_copy = Discourse.store.download_safe(upload)
|
||||
path = external_copy&.path
|
||||
else
|
||||
path = Discourse.store.path_for(upload)
|
||||
end
|
||||
|
||||
@@ -160,13 +160,8 @@ class Upload < ActiveRecord::Base
|
||||
# this is relatively cheap once cached
|
||||
original_path = Discourse.store.path_for(self)
|
||||
if original_path.blank?
|
||||
external_copy =
|
||||
begin
|
||||
Discourse.store.download(self)
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
original_path = external_copy.try(:path)
|
||||
external_copy = Discourse.store.download_safe(self)
|
||||
original_path = external_copy&.path
|
||||
end
|
||||
|
||||
image_info =
|
||||
@@ -361,13 +356,7 @@ class Upload < ActiveRecord::Base
|
||||
if local?
|
||||
Discourse.store.path_for(self)
|
||||
else
|
||||
begin
|
||||
Discourse.store.download(self)&.path
|
||||
rescue OpenURI::HTTPError => e
|
||||
# Some issue with downloading the image from a remote store.
|
||||
# Assume the upload is broken and save an empty string to prevent re-evaluation
|
||||
nil
|
||||
end
|
||||
Discourse.store.download_safe(self)&.path
|
||||
end
|
||||
|
||||
if local_path.nil?
|
||||
|
||||
Reference in New Issue
Block a user