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:
Ted Johansson
2023-05-11 17:27:27 +08:00
committed by GitHub
parent 4e846b69c4
commit b837459e1d
6 changed files with 68 additions and 41 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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?