From bf5611f7ebd9bf8dd23350e78c70829054707542 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Mon, 1 Feb 2021 20:49:32 -0300 Subject: [PATCH] FIX: Make discobot certificate faster/non blocking (#11344) This moves the way we add the user avatar and site logo to the discobot certificates from embeded base64 png to just using the files urls in the href to the image tag. This will make generation faster and the certificate smaller overall, but it can't be used in a `img` tag anymore, since SVGs in `img` tags don't load the external images In order to work around that we will move the certificate in posts to an iframe, which works fine without any user visible changes. For this to be possible the plugin automatically adds the site current domain to the list of allowed iframe origins. --- .../lib/discourse_narrative_bot/base.rb | 2 +- .../certificate_generator.rb | 58 +++++-------------- .../templates/advanced_user.svg.erb | 7 ++- .../templates/new_user.svg.erb | 6 +- plugins/discourse-narrative-bot/plugin.rb | 20 +++---- .../requests/discobot_certificate_spec.rb | 4 +- 6 files changed, 33 insertions(+), 64 deletions(-) diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.rb index 066a0bdeacb..46d50d15974 100644 --- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.rb +++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/base.rb @@ -137,7 +137,7 @@ module DiscourseNarrativeBot src = Discourse.base_url + DiscourseNarrativeBot::Engine.routes.url_helpers.certificate_path(options) alt = CGI.escapeHTML(I18n.t("#{self.class::I18N_KEY}.certificate.alt")) - "#{alt}" + "