Fix HTML email preview in the checks list

This commit is contained in:
Pēteris Caune 2021-03-10 12:29:20 +02:00
parent ad886fe157
commit 57336187a7
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
6 changed files with 24 additions and 6 deletions

View File

@ -27,7 +27,7 @@
line-height: 1em;
}
#email-body-html-iframe {
#email-body-html iframe {
border: 0;
width: 100%;
height: 500px;

View File

@ -59,6 +59,18 @@ $(function () {
var lastPingUrl = base + "/checks/" + code + "/last_ping/";
$.get(lastPingUrl, function(data) {
$("#ping-details-body" ).html(data);
var htmlPre = $("#email-body-html pre");
if (htmlPre.length) {
var opts = {USE_PROFILES: {html: true}};
var clean = DOMPurify.sanitize(htmlPre.text(), opts);
var blob = new Blob([clean], {type: "text/html; charset=utf-8"});
var iframe = document.createElement("iframe");
iframe.sandbox = "";
iframe.src = URL.createObjectURL(blob);
htmlPre.replaceWith(iframe);
}
});
var logUrl = base + "/checks/" + code + "/log/";

View File

@ -139,8 +139,11 @@ $(function () {
var clean = DOMPurify.sanitize(htmlPre.text(), opts);
var blob = new Blob([clean], {type: "text/html; charset=utf-8"});
htmlPre.remove();
document.getElementById("email-body-html-iframe").src = URL.createObjectURL(blob);
var iframe = document.createElement("iframe");
iframe.sandbox = "";
iframe.src = URL.createObjectURL(blob);
htmlPre.replaceWith(iframe);
}
}
);

View File

@ -12,8 +12,11 @@ $(function () {
var clean = DOMPurify.sanitize(htmlPre.text(), opts);
var blob = new Blob([clean], {type: "text/html; charset=utf-8"});
htmlPre.remove();
document.getElementById("email-body-html-iframe").src = URL.createObjectURL(blob);
var iframe = document.createElement("iframe");
iframe.sandbox = "";
iframe.src = URL.createObjectURL(blob);
htmlPre.replaceWith(iframe);
}
});

View File

@ -96,6 +96,7 @@
<script src="{% static 'js/selectize.min.js' %}"></script>
<script src="{% static 'js/nouislider.min.js' %}"></script>
<script src="{% static 'js/clipboard.min.js' %}"></script>
<script src="{% static 'js/purify.min.js' %}"></script>
<script src="{% static 'js/update-timeout-modal.js' %}"></script>
<script src="{% static 'js/adaptive-setinterval.js' %}"></script>
<script src="{% static 'js/checks.js' %}"></script>

View File

@ -106,7 +106,6 @@
{% if html %}
<div id="email-body-html" class="tab-pane">
<pre>{{ html }}</pre>
<iframe id="email-body-html-iframe" sandbox></iframe>
</div>
{% endif %}
</div>