Skip to content

A platform for community discussion. Free, open, simple.

DEV: send url string to FileHelper and refactor another open-uri call

Blake Erickson73e33ce24370
diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/certificate_generator.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/certificate_generator.rb
index a66dcba191e..a158521149f 100644
--- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/certificate_generator.rb
+++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/certificate_generator.rb
@@ -93,7 +93,12 @@ module DiscourseNarrativeBot
end
def fetch_image(url)
- URI(url).open('rb', redirect: true, allow_redirections: :all).read
+ FileHelper.download(
+ url.to_s,
+ max_file_size: SiteSetting.max_image_size_kb.kilobytes,
+ tmp_file_name: 'narrative-bot-logo',
+ follow_redirect: true
+ )&.read
rescue OpenURI::HTTPError
# Ignore if fetching image returns a non 200 response
end
diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rb
index 31949915f4b..54e97a05e7a 100644
--- a/plugins/discourse-narrative-bot/plugin.rb
+++ b/plugins/discourse-narrative-bot/plugin.rb
@@ -110,11 +110,11 @@ after_initialize do
def fetch_avatar_url(user)
avatar_url = UrlHelper.absolute(Discourse.base_uri + user.avatar_template.gsub('{size}', '250'))
FileHelper.download(
- avatar_url,
+ avatar_url.to_s,
max_file_size: SiteSetting.max_image_size_kb.kilobytes,
tmp_file_name: 'narrative-bot-avatar',
follow_redirect: true
- ).read
+ )&.read
rescue OpenURI::HTTPError
# Ignore if fetching image returns a non 200 response
end