Improve media-tag export in pad to work with existing CSP

pull/1/head
yflory 7 years ago
parent 3e4faf1be1
commit c1d05a00ba

@ -207,6 +207,13 @@ define([], function () {
return Array.prototype.slice.call(A); return Array.prototype.slice.call(A);
}; };
Util.blobToImage = function (blob, cb) {
var reader = new FileReader();
reader.onloadend = function() {
cb(reader.result);
};
reader.readAsDataURL(blob);
};
Util.blobURLToImage = function (url, cb) { Util.blobURLToImage = function (url, cb) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.onload = function() { xhr.onload = function() {

@ -1498,10 +1498,15 @@ define([
if (decrypted.callback) { if (decrypted.callback) {
var cb = decrypted.callback; var cb = decrypted.callback;
cb(function (mediaObject) { cb(function (mediaObject) {
if (mediaObject.type !== 'download') { return; } var root = mediaObject.element;
var root = mediaObject.rootElement;
if (!root) { return; } if (!root) { return; }
if (mediaObject.type === 'image') {
$(root).data('blob', decrypted.blob);
}
if (mediaObject.type !== 'download') { return; }
var metadata = decrypted.metadata; var metadata = decrypted.metadata;
var title = ''; var title = '';

@ -477,9 +477,11 @@ define([
var exportMediaTags = function (inner, cb) { var exportMediaTags = function (inner, cb) {
var $clone = $(inner).clone(); var $clone = $(inner).clone();
nThen(function (waitFor) { nThen(function (waitFor) {
$clone.find('media-tag > img').each(function (i, el) { $(inner).find('media-tag').each(function (i, el) {
Util.blobURLToImage($(el).attr('src'), waitFor(function (imgSrc) { if (!$(el).data('blob')) { return; }
$(el).attr('src', imgSrc); Util.blobToImage($(el).data('blob'), waitFor(function (imgSrc) {
$clone.find('media-tag[src="' + $(el).attr('src') + '"] img')
.attr('src', imgSrc);
})); }));
}); });
}).nThen(function () { }).nThen(function () {

Loading…
Cancel
Save