Add a Share entry in the drive's context menu

pull/1/head
yflory 6 years ago
parent e0b7f3f965
commit a117e329dc

@ -460,6 +460,7 @@ define([
var pathname = config.pathname;
var hashes = config.hashes;
var common = config.common;
var fileData = config.fileData;
if (!hashes.fileHash) { throw new Error("You must provide a file hash"); }
var url = origin + pathname + '#' + hashes.fileHash;
@ -495,7 +496,7 @@ define([
UI.dialog.selectable(common.getMediatagScript()),
h('p', Messages.fileEmbedTag),
h('br'),
UI.dialog.selectable(common.getMediatagFromHref(url)),
UI.dialog.selectable(common.getMediatagFromHref(fileData)),
]);
var embedButtons = [{
name: Messages.cancel,
@ -505,7 +506,7 @@ define([
className: 'primary',
name: Messages.share_mediatagCopy,
onClick: function () {
var v = common.getMediatagFromHref(url);
var v = common.getMediatagFromHref(fileData);
var success = Clipboard.copy(v);
if (success) { UI.log(Messages.shareSuccess); }
},

@ -112,9 +112,14 @@ define([
var origin = ctx.metadataMgr.getPrivateData().origin;
return '<script src="' + origin + '/common/media-tag-nacl.min.js"></script>';
};
funcs.getMediatagFromHref = function () {
funcs.getMediatagFromHref = function (obj) {
var data = ctx.metadataMgr.getPrivateData();
var secret = Hash.getSecrets('file', data.availableHashes.fileHash, data.password);
var secret;
if (obj) {
secret = Hash.getSecrets('file', obj.hash, obj.password);
} else {
secret = Hash.getSecrets('file', data.availableHashes.fileHash, data.password);
}
if (secret.keys && secret.channel) {
var key = Hash.encodeBase64(secret.keys && secret.keys.cryptKey);
var hexFileName = secret.channel;

@ -258,6 +258,10 @@ define([
'tabindex': '-1',
'data-icon': faReadOnly,
}, Messages.fc_open_ro)),
h('li', h('a.cp-app-drive-context-share.dropdown-item', {
'tabindex': '-1',
'data-icon': 'fa-shhare-alt',
}, Messages.shareButton)),
h('li', h('a.cp-app-drive-context-openparent.dropdown-item', {
'tabindex': '-1',
'data-icon': faShowParent,
@ -859,6 +863,7 @@ define([
containsFolder = true;
hide.push('openro');
hide.push('properties');
hide.push('share');
hide.push('hashtag');
}
// If we're in the trash, hide restore and properties for non-root elements
@ -905,11 +910,11 @@ define([
show = ['newfolder', 'newsharedfolder', 'newdoc'];
break;
case 'tree':
show = ['open', 'openro', 'rename', 'delete', 'deleteowned', 'removesf',
show = ['open', 'openro', 'share', 'rename', 'delete', 'deleteowned', 'removesf',
'newfolder', 'properties', 'hashtag'];
break;
case 'default':
show = ['open', 'openro', 'openparent', 'delete', 'deleteowned', 'properties', 'hashtag'];
show = ['open', 'openro', 'share', 'openparent', 'delete', 'deleteowned', 'properties', 'hashtag'];
break;
case 'trashtree': {
show = ['empty'];
@ -3042,6 +3047,46 @@ define([
openFile(null, href);
});
}
else if ($(this).hasClass('cp-app-drive-context-share')) {
if (paths.length !== 1) { return; }
el = manager.find(paths[0].path);
var data, parsed, modal;
if (manager.isSharedFolder(el)) {
data = manager.getSharedFolderData(el);
parsed = Hash.parsePadUrl(data.href);
modal = UIElements.createSFShareModal({
origin: APP.origin,
pathname: "/drive/",
hashes: {
editHash: parsed.hash
}
});
} else {
data = manager.getFileData(el);
parsed = Hash.parsePadUrl(data.href);
var roParsed = Hash.parsePadUrl(data.roHref);
var type = parsed.type || roParsed.type;
console.log(parsed);
var padData = {
origin: APP.origin,
pathname: "/" + type + "/",
hashes: {
editHash: parsed.hash,
viewHash: roParsed.hash,
fileHash: parsed.hash
},
fileData: {
hash: parsed.hash,
password: data.password
},
common: common
};
modal = type === 'file' ? UIElements.createFileShareModal(padData)
: UIElements.createShareModal(padData);
modal = UI.dialog.tabs(modal);
}
UI.openCustomModal(modal);
}
else if ($(this).hasClass('cp-app-drive-context-newfolder')) {
if (paths.length !== 1) { return; }
var onFolderCreated = function (err, info) {

Loading…
Cancel
Save