diff --git a/app/controllers/discourse_ai/ai_bot/artifacts_controller.rb b/app/controllers/discourse_ai/ai_bot/artifacts_controller.rb index 3ae65ef8..ff7f3260 100644 --- a/app/controllers/discourse_ai/ai_bot/artifacts_controller.rb +++ b/app/controllers/discourse_ai/ai_bot/artifacts_controller.rb @@ -19,22 +19,33 @@ module DiscourseAi raise Discourse::NotFound if !guardian.can_see?(post) end + name = artifact.name + + if params[:version].present? + artifact = artifact.versions.find_by(version_number: params[:version]) + raise Discourse::NotFound if !artifact + end + + js = artifact.js || "" + if !js.match?(%r{\A\s*}mi) + mod = "" + mod = " type=\"module\"" if js.match?(/\A\s*import.*/) + js = "\n#{js}\n" + end # Prepare the inner (untrusted) HTML document untrusted_html = <<~HTML - #{ERB::Util.html_escape(artifact.name)} + #{ERB::Util.html_escape(name)} #{artifact.html} - + #{js} HTML @@ -45,7 +56,7 @@ module DiscourseAi - #{ERB::Util.html_escape(artifact.name)} + #{ERB::Util.html_escape(name)}