use a standard function for creating basic media-tags

pull/1/head
ansuz 3 years ago
parent 7703085aeb
commit 575269e5a1

@ -507,7 +507,7 @@ define([
var fileHost = privateData.fileHost || privateData.origin; var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(secret.channel); var src = fileHost + Hash.getBlobPathFromHex(secret.channel);
var key = Hash.encodeBase64(secret.keys.cryptKey); var key = Hash.encodeBase64(secret.keys.cryptKey);
var mt = '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + key + '"></media-tag>'; var mt = UI.mediaTag(src, key).outerHTML;
editor.replaceSelection(mt); editor.replaceSelection(mt);
} }
}; };

@ -41,6 +41,15 @@ define([
return e; return e;
}; };
// FIXME almost everywhere this is used would also be
// a good candidate for sframe-common's getMediatagFromHref
UI.mediaTag = function (src, key) {
return h('media-tag', {
src: src,
'data-crypto-key': 'cryptpad:' + key,
});
};
var findCancelButton = UI.findCancelButton = function (root) { var findCancelButton = UI.findCancelButton = function (root) {
if (root) { if (root) {
return $(root).find('button.cancel').last(); return $(root).find('button.cancel').last();

@ -676,7 +676,6 @@ define([
if (el.childNodes.length === 1 && el.childNodes[0].nodeType === 3) { if (el.childNodes.length === 1 && el.childNodes[0].nodeType === 3) {
var type = el.getAttribute('data-plugin'); var type = el.getAttribute('data-plugin');
var plugin = plugins[type]; var plugin = plugins[type];
console.log(type);
if (!plugin) { return; } if (!plugin) { return; }
var src = canonicalizeMermaidSource(el.childNodes[0].wholeText); var src = canonicalizeMermaidSource(el.childNodes[0].wholeText);
el.setAttribute(plugin.attr, src); el.setAttribute(plugin.attr, src);

@ -127,9 +127,8 @@ define([
if (e || !data) { return void displayDefault(); } if (e || !data) { return void displayDefault(); }
if (typeof data !== "number") { return void displayDefault(); } if (typeof data !== "number") { return void displayDefault(); }
if (Util.bytesToMegabytes(data) > 0.5) { return void displayDefault(); } if (Util.bytesToMegabytes(data) > 0.5) { return void displayDefault(); }
var $img = $('<media-tag>').appendTo($container); var mt = UI.mediaTag(src, cryptKey);
$img.attr('src', src); var $img = $(mt).appendTo($container);
$img.attr('data-crypto-key', 'cryptpad:' + cryptKey);
MT.displayMediatagImage(common, $img, function (err, $image) { MT.displayMediatagImage(common, $img, function (err, $image) {
if (err) { return void console.error(err); } if (err) { return void console.error(err); }
centerImage($img, $image); centerImage($img, $image);

@ -748,8 +748,8 @@ define([
var privateDat = cpNfInner.metadataMgr.getPrivateData(); var privateDat = cpNfInner.metadataMgr.getPrivateData();
var origin = privateDat.fileHost || privateDat.origin; var origin = privateDat.fileHost || privateDat.origin;
var src = data.src = data.src.slice(0,1) === '/' ? origin + data.src : data.src; var src = data.src = data.src.slice(0,1) === '/' ? origin + data.src : data.src;
mediaTagEmbedder($('<media-tag src="' + src + var mt = UI.mediaTag(src, data.key);
'" data-crypto-key="cryptpad:' + data.key + '"></media-tag>'), data); mediaTagEmbedder($(mt), data);
}); });
}).appendTo(toolbar.$bottomL).hide(); }).appendTo(toolbar.$bottomL).hide();
}; };

@ -145,8 +145,7 @@ define([
var hexFileName = secret.channel; var hexFileName = secret.channel;
var origin = data.fileHost || data.origin; var origin = data.fileHost || data.origin;
var src = origin + Hash.getBlobPathFromHex(hexFileName); var src = origin + Hash.getBlobPathFromHex(hexFileName);
return '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + key + '">' + return UI.mediaTag(src, key).outerHTML;
'</media-tag>';
} }
return; return;
}; };

@ -289,7 +289,7 @@ define([
var fileHost = privateData.fileHost || privateData.origin; var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(secret.channel); var src = fileHost + Hash.getBlobPathFromHex(secret.channel);
var key = Hash.encodeBase64(secret.keys.cryptKey); var key = Hash.encodeBase64(secret.keys.cryptKey);
var mt = '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + key + '"></media-tag>'; var mt = UI.mediaTag(src, key).outerHTML;
editor.replaceSelection(mt); editor.replaceSelection(mt);
} }
}; };

@ -955,7 +955,7 @@ define([
var fileHost = privateData.fileHost || privateData.origin; var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(secret.channel); var src = fileHost + Hash.getBlobPathFromHex(secret.channel);
var key = Hash.encodeBase64(secret.keys.cryptKey); var key = Hash.encodeBase64(secret.keys.cryptKey);
var mt = '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + key + '"></media-tag>'; var mt = UI.mediaTag(src, key).outerHTML;
APP.editor.replaceSelection(mt); APP.editor.replaceSelection(mt);
} }
}; };
@ -1235,7 +1235,7 @@ define([
common.openFilePicker(pickerCfg, function (data) { common.openFilePicker(pickerCfg, function (data) {
if (data.type === 'file' && APP.editor) { if (data.type === 'file' && APP.editor) {
common.setPadAttribute('atime', +new Date(), null, data.href); common.setPadAttribute('atime', +new Date(), null, data.href);
var mt = '<media-tag src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '"></media-tag>'; var mt = UI.mediaTag(data.src, data.key).outerHTML;
APP.editor.replaceSelection(mt); APP.editor.replaceSelection(mt);
return; return;
} }

@ -556,7 +556,7 @@ define([
var fileHost = privateData.fileHost || privateData.origin; var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(secret.channel); var src = fileHost + Hash.getBlobPathFromHex(secret.channel);
var key = Hash.encodeBase64(secret.keys.cryptKey); var key = Hash.encodeBase64(secret.keys.cryptKey);
var mt = '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + key + '"></media-tag>'; var mt = UI.mediaTag(src, key).outerHTML;
editor.replaceSelection(mt); editor.replaceSelection(mt);
} }
}; };

Loading…
Cancel
Save