diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index 3d28d126a..e60f734d0 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -362,6 +362,9 @@ define([ }); }; + Messages.pad_mediatagShare = "Share file"; // XXX + Messages.pad_mediatagOpen = "Open file"; // XXX + var mediatagContextMenu; MT.importMediaTagMenu = function (common) { if (mediatagContextMenu) { return mediatagContextMenu; } @@ -377,6 +380,14 @@ define([ 'tabindex': '-1', 'data-icon': "fa-eye", }, Messages.pad_mediatagPreview)), + h('li.cp-svg', h('a.cp-app-code-context-openin.dropdown-item', { + 'tabindex': '-1', + 'data-icon': "fa-external-link", + }, Messages.pad_mediatagOpen)), + h('li.cp-svg', h('a.cp-app-code-context-share.dropdown-item', { + 'tabindex': '-1', + 'data-icon': "fa-shhare-alt", + }, Messages.pad_mediatagShare)), h('li', h('a.cp-app-code-context-saveindrive.dropdown-item', { 'tabindex': '-1', 'data-icon': "fa-cloud-upload", @@ -419,6 +430,21 @@ define([ else if ($this.hasClass("cp-app-code-context-open")) { $mt.trigger('preview'); } + else if ($this.hasClass("cp-app-code-context-openin")) { + var hash = common.getHashFromMediaTag($mt); + common.openURL(Hash.hashToHref(hash, 'file')); + } + else if ($this.hasClass("cp-app-code-context-share")) { + var data = { + file: true, + pathname: '/file/', + hashes: { + fileHash: common.getHashFromMediaTag($mt) + }, + title: Util.find($mt[0], ['_mediaObject', 'name']) || '' + }; + common.getSframeChannel().event('EV_SHARE_OPEN', data); + } }); return m; diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 4198a649a..7a00516a5 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -142,7 +142,7 @@ define([ } return; }; - funcs.importMediaTag = function ($mt) { + var getMtData = function ($mt) { if (!$mt || !$mt.is('media-tag')) { return; } var chanStr = $mt.attr('src'); var keyStr = $mt.attr('data-crypto-key'); @@ -154,10 +154,27 @@ define([ var channel = src.replace(/\/blob\/[0-9a-f]{2}\//i, ''); // Get key var key = keyStr.replace(/cryptpad:/i, ''); + return { + channel: channel, + key: key + }; + }; + funcs.getHashFromMediaTag = function ($mt) { + var data = getMtData($mt); + if (!data) { return; } + return Hash.getFileHashFromKeys({ + version: 1, + channel: data.channel, + keys: { fileKeyStr: data.key } + }); + }; + funcs.importMediaTag = function ($mt) { + var data = getMtData($mt); + if (!data) { return; } var metadata = $mt[0]._mediaObject._blob.metadata; ctx.sframeChan.query('Q_IMPORT_MEDIATAG', { - channel: channel, - key: key, + channel: data.channel, + key: data.key, name: metadata.name, type: metadata.type, owners: metadata.owners diff --git a/www/secureiframe/inner.js b/www/secureiframe/inner.js index c20d53a80..4d5b8ee4f 100644 --- a/www/secureiframe/inner.js +++ b/www/secureiframe/inner.js @@ -52,10 +52,10 @@ define([ : Share.getShareModal; f(common, { origin: priv.origin, - pathname: priv.pathname, - password: priv.password, - isTemplate: priv.isTemplate, - hashes: priv.hashes, + pathname: data.pathname || priv.pathname, + password: data.hashes ? '' : priv.password, + isTemplate: data.hashes ? false : priv.isTemplate, + hashes: data.hashes || priv.hashes, common: common, title: data.title, versionHash: data.versionHash, @@ -64,8 +64,8 @@ define([ hideIframe(); }, fileData: { - hash: priv.hashes.fileHash, - password: priv.password + hash: (data.hashes && data.hashes.fileHash) || priv.hashes.fileHash, + password: data.hashes ? '' : priv.password } }, function (e, modal) { if (e) { console.error(e); }