mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: OptimizedImage#filesize (#10095)
`OptimizedImage#filesize` calls `Discourse.store.download` with an OptimizedImage as an argument. It would in turn attempt to call `#original_filename` and `#secure?` on that object. Both would fail as these methods do not exist on OptimizedImage, only on Upload. We didn't know about these issues because: 1. `#calculate_filesize` is not called often, because the filesize is saved on OptimizedImage creation, so it's used mostly for manual filesize recalculation 2. we were using `rescue nil` which swallows all errors
This commit is contained in:
@@ -76,17 +76,19 @@ module FileStore
|
||||
not_implemented
|
||||
end
|
||||
|
||||
def download(upload, max_file_size_kb: nil)
|
||||
DistributedMutex.synchronize("download_#{upload.sha1}", validity: 3.minutes) do
|
||||
filename = "#{upload.sha1}#{File.extname(upload.original_filename)}"
|
||||
def download(object, max_file_size_kb: nil)
|
||||
DistributedMutex.synchronize("download_#{object.sha1}", validity: 3.minutes) do
|
||||
extension = File.extname(object.respond_to?(:original_filename) ? object.original_filename : object.url)
|
||||
filename = "#{object.sha1}#{extension}"
|
||||
file = get_from_cache(filename)
|
||||
|
||||
if !file
|
||||
max_file_size_kb ||= [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes
|
||||
|
||||
url = upload.secure? ?
|
||||
Discourse.store.signed_url_for_path(upload.url) :
|
||||
Discourse.store.cdn_url(upload.url)
|
||||
secure = object.respond_to?(:secure) ? object.secure? : object.upload.secure?
|
||||
url = secure ?
|
||||
Discourse.store.signed_url_for_path(object.url) :
|
||||
Discourse.store.cdn_url(object.url)
|
||||
|
||||
url = SiteSetting.scheme + ":" + url if url =~ /^\/\//
|
||||
file = FileHelper.download(
|
||||
@@ -95,6 +97,7 @@ module FileStore
|
||||
tmp_file_name: "discourse-download",
|
||||
follow_redirect: true
|
||||
)
|
||||
|
||||
cache_file(file, filename)
|
||||
file = get_from_cache(filename)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user