module DiscourseNarrativeBot
class CertificateGenerator
def initialize(user, date)
@user = user
@date = I18n.l(Date.parse(date), format: :date_only)
@discobot_user = User.find(-2)
end
def new_user_track
width = 538.583 # Default width for the SVG
svg = <<~SVG
SVG
end
def advanced_user_track
width = 722.8 # Default width for the SVG
<<~SVG
SVG
end
private
def name
@user.username.titleize
end
def logo_group(size, width, height)
begin
uri = URI(SiteSetting.logo_small_url)
logo_uri =
if uri.host.blank? || uri.scheme.blank?
URI("#{Discourse.base_url}/#{uri.path}")
else
uri
end
<<~URL
URL
rescue URI::InvalidURIError
''
end
end
def base64_image_link(url)
if image = fetch_image(url)
"xlink:href=\"data:image/png;base64,#{Base64.strict_encode64(image)}\""
else
""
end
end
def fetch_image(url)
URI(url).open('rb', redirect: true, allow_redirections: :all).read
rescue OpenURI::HTTPError
# Ignore if fetching image returns a non 200 response
end
def avatar_url
UrlHelper.absolute(Discourse.base_uri + @user.avatar_template.gsub('{size}', '250'))
end
end
end