From 08b4753843917d62a2d4480052e1d590fdc45315 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Thu, 14 Nov 2019 05:23:51 -0700 Subject: [PATCH] DEV: Use FileHelper instead for downloading narrative bot avatar Follow up to https://github.com/discourse/discourse/commit/b69450bee2d6d181d2db32d80c552b8c32a469b9 Using FileHelper here allows us to not have to use another require for open-uri and gives us all the benefits of FileHelper. --- plugins/discourse-narrative-bot/plugin.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/discourse-narrative-bot/plugin.rb b/plugins/discourse-narrative-bot/plugin.rb index da8f9dd015c..e3e6afea78a 100644 --- a/plugins/discourse-narrative-bot/plugin.rb +++ b/plugins/discourse-narrative-bot/plugin.rb @@ -6,8 +6,6 @@ # authors: Nick Sahler, Alan Tan # url: https://github.com/discourse/discourse/tree/master/plugins/discourse-narrative-bot -require 'open-uri' - enabled_site_setting :discourse_narrative_bot_enabled hide_plugin if self.respond_to?(:hide_plugin) @@ -111,7 +109,12 @@ after_initialize do def fetch_avatar_url(user) avatar_url = UrlHelper.absolute(Discourse.base_uri + user.avatar_template.gsub('{size}', '250')) - open(avatar_url, 'rb').read + FileHelper.download( + avatar_url, + max_file_size: SiteSetting.max_image_size_kb.kilobytes, + tmp_file_name: 'narrative-bot-avatar', + follow_redirect: true + ) rescue OpenURI::HTTPError # Ignore if fetching image returns a non 200 response end