mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: Don't rate limit gravatar downloads
This commit is contained in:
parent
cdbe027c1c
commit
0a08c18a14
|
@ -23,7 +23,8 @@ class UserAvatar < ActiveRecord::Base
|
||||||
tempfile = FileHelper.download(
|
tempfile = FileHelper.download(
|
||||||
gravatar_url,
|
gravatar_url,
|
||||||
max_file_size: SiteSetting.max_image_size_kb.kilobytes,
|
max_file_size: SiteSetting.max_image_size_kb.kilobytes,
|
||||||
tmp_file_name: "gravatar"
|
tmp_file_name: "gravatar",
|
||||||
|
skip_rate_limit: true
|
||||||
)
|
)
|
||||||
if tempfile
|
if tempfile
|
||||||
upload = UploadCreator.new(tempfile, 'gravatar.png', origin: gravatar_url, type: "avatar").create_for(user_id)
|
upload = UploadCreator.new(tempfile, 'gravatar.png', origin: gravatar_url, type: "avatar").create_for(user_id)
|
||||||
|
|
|
@ -7,11 +7,21 @@ class FileHelper
|
||||||
filename =~ images_regexp
|
filename =~ images_regexp
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.download(url, max_file_size:, tmp_file_name:, follow_redirect: false, read_timeout: 5)
|
def self.download(url,
|
||||||
|
max_file_size:,
|
||||||
|
tmp_file_name:,
|
||||||
|
follow_redirect: false,
|
||||||
|
read_timeout: 5,
|
||||||
|
skip_rate_limit: false)
|
||||||
|
|
||||||
url = "https:" + url if url.start_with?("//")
|
url = "https:" + url if url.start_with?("//")
|
||||||
raise Discourse::InvalidParameters.new(:url) unless url =~ /^https?:\/\//
|
raise Discourse::InvalidParameters.new(:url) unless url =~ /^https?:\/\//
|
||||||
|
|
||||||
uri = FinalDestination.new(url, max_redirects: follow_redirect ? 5 : 1).resolve
|
uri = FinalDestination.new(
|
||||||
|
url,
|
||||||
|
max_redirects: follow_redirect ? 5 : 1,
|
||||||
|
skip_rate_limit: skip_rate_limit
|
||||||
|
).resolve
|
||||||
return unless uri.present?
|
return unless uri.present?
|
||||||
|
|
||||||
extension = File.extname(uri.path)
|
extension = File.extname(uri.path)
|
||||||
|
|
|
@ -99,7 +99,9 @@ class FinalDestination
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rate limit how often this IP can be crawled
|
# Rate limit how often this IP can be crawled
|
||||||
RateLimiter.new(nil, "crawl-destination-ip:#{address_s}", 100, 1.hour).performed!
|
unless @opts[:skip_rate_limit]
|
||||||
|
RateLimiter.new(nil, "crawl-destination-ip:#{address_s}", 100, 1.hour).performed!
|
||||||
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
rescue RateLimiter::LimitExceeded
|
rescue RateLimiter::LimitExceeded
|
||||||
|
|
Loading…
Reference in New Issue
Block a user