From 5be37f2e4548e5a967c7baf81152f69678bfd964 Mon Sep 17 00:00:00 2001 From: yflory Date: Sat, 13 Jul 2019 15:23:32 +0200 Subject: [PATCH 01/38] Unified metadata --- historyKeeper.js | 46 +++++++++------------ www/common/common-messenger.js | 6 ++- www/common/outer/async-store.js | 11 +++-- www/common/outer/onlyoffice.js | 8 ++-- www/common/sframe-chainpad-netflux-outer.js | 11 ++--- www/common/sframe-common-outer.js | 10 +++-- 6 files changed, 43 insertions(+), 49 deletions(-) diff --git a/historyKeeper.js b/historyKeeper.js index 03c767506..342910ad5 100644 --- a/historyKeeper.js +++ b/historyKeeper.js @@ -396,32 +396,35 @@ module.exports.create = function (cfg) { // parsed[3] is the last known hash (optionnal) sendMsg(ctx, user, [seq, 'ACK']); channelName = parsed[1]; - var validateKey = parsed[2]; - var lastKnownHash = parsed[3]; - var owners; - var expire; - if (parsed[2] && typeof parsed[2] === "object") { - validateKey = parsed[2].validateKey; - lastKnownHash = parsed[2].lastKnownHash; - owners = parsed[2].owners; - if (parsed[2].expire) { - expire = +parsed[2].expire * 1000 + (+new Date()); + var config = parsed[2]; + var metadata = {}; + var lastKnownHash; + if (config && typeof config === "object") { + lastKnownHash = config.lastKnownHash; + metadata = config.metadata || {}; + if (metadata.expire) { + metadata.expire = +metadata.expire * 1000 + (+new Date()); } + } else if (config) { + // This is the old way: parsed[2] is the validateKey and parsed[3] is the last known hash + lastKnownHash = parsed[3]; + metadata.validateKey = parsed[2]; } + metadata.channel = channelName; nThen(function (waitFor) { if (!tasks) { return; } // tasks are not supported - if (typeof(expire) !== 'number' || !expire) { return; } + if (typeof(metadata.expire) !== 'number' || !metadata.expire) { return; } // the fun part... // the user has said they want this pad to expire at some point - tasks.write(expire, "EXPIRE", [ channelName ], waitFor(function (err) { + tasks.write(metadata.expire, "EXPIRE", [ channelName ], waitFor(function (err) { if (err) { // if there is an error, we don't want to crash the whole server... // just log it, and if there's a problem you'll be able to fix it // at a later date with the provided information Log.error('HK_CREATE_EXPIRE_TASK', err); - Log.info('HK_INVALID_EXPIRE_TASK', JSON.stringify([expire, 'EXPIRE', channelName])); + Log.info('HK_INVALID_EXPIRE_TASK', JSON.stringify([metadata.expire, 'EXPIRE', channelName])); } })); }).nThen(function (waitFor) { @@ -482,20 +485,9 @@ module.exports.create = function (cfg) { // the first message in the file const chan = ctx.channels[channelName]; if (msgCount === 0 && !historyKeeperKeys[channelName] && chan && chan.indexOf(user) > -1) { - var key = {}; - key.channel = channelName; - if (validateKey) { - key.validateKey = validateKey; - } - if (owners) { - key.owners = owners; - } - if (expire) { - key.expire = expire; - } - historyKeeperKeys[channelName] = key; - storeMessage(ctx, chan, JSON.stringify(key), false, undefined); - sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(key)]); + historyKeeperKeys[channelName] = metadata; + storeMessage(ctx, chan, JSON.stringify(metadata), false, undefined); + sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(metadata)]); } // End of history message: diff --git a/www/common/common-messenger.js b/www/common/common-messenger.js index 1102f94a2..365c8be40 100644 --- a/www/common/common-messenger.js +++ b/www/common/common-messenger.js @@ -422,8 +422,10 @@ define([ var friend = getFriendFromChannel(chan.id) || {}; var cfg = { - validateKey: keys ? keys.validateKey : undefined, - owners: [proxy.edPublic, friend.edPublic], + metadata: { + validateKey: keys ? keys.validateKey : undefined, + owners: [proxy.edPublic, friend.edPublic], + }, lastKnownHash: data.lastKnownHash }; var msg = ['GET_HISTORY', chan.id, cfg]; diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index ca7e4cd7c..063d23ad8 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1191,10 +1191,7 @@ define([ }, noChainPad: true, channel: data.channel, - validateKey: data.validateKey, - owners: data.owners, - password: data.password, - expire: data.expire, + metadata: data.metadata, network: store.network, //readOnly: data.readOnly, onConnect: function (wc, sendMessage) { @@ -1441,14 +1438,16 @@ define([ websocketURL: NetConfig.getWebsocketURL(), channel: secret.channel, readOnly: false, - validateKey: secret.keys.validateKey || undefined, crypto: Crypto.createEncryptor(secret.keys), userName: 'sharedFolder', logLevel: 1, ChainPad: ChainPad, classic: true, network: store.network, - owners: owners + metadata: { + validateKey: secret.keys.validateKey || undefined, + owners: owners + } }; var rt = Listmap.create(listmapConfig); store.sharedFolders[id] = rt; diff --git a/www/common/outer/onlyoffice.js b/www/common/outer/onlyoffice.js index 70bc413ec..37359d757 100644 --- a/www/common/outer/onlyoffice.js +++ b/www/common/outer/onlyoffice.js @@ -92,9 +92,11 @@ define([ var hk = network.historyKeeper; var cfg = { validateKey: obj.validateKey, - lastKnownHash: chan.lastKnownHash || chan.lastCpHash, - owners: obj.owners, - expire: obj.expire + metadata: { + lastKnownHash: chan.lastKnownHash || chan.lastCpHash, + owners: obj.owners, + expire: obj.expire + } }; var msg = ['GET_HISTORY', wc.id, cfg]; // Add the validateKey if we are the channel creator and we have a validateKey diff --git a/www/common/sframe-chainpad-netflux-outer.js b/www/common/sframe-chainpad-netflux-outer.js index a91f9f6d1..9dbfb1816 100644 --- a/www/common/sframe-chainpad-netflux-outer.js +++ b/www/common/sframe-chainpad-netflux-outer.js @@ -23,14 +23,12 @@ define([], function () { var start = function (conf) { var channel = conf.channel; var Crypto = conf.crypto; - var validateKey = conf.validateKey; var isNewHash = conf.isNewHash; var readOnly = conf.readOnly || false; var padRpc = conf.padRpc; var sframeChan = conf.sframeChan; - var password = conf.password; - var owners = conf.owners; - var expire = conf.expire; + var metadata= conf.metadata || {}; + var validateKey = metadata.validateKey; var onConnect = conf.onConnect || function () { }; conf = undefined; @@ -127,11 +125,8 @@ define([], function () { // join the netflux network, promise to handle opening of the channel padRpc.joinPad({ channel: channel || null, - validateKey: validateKey, readOnly: readOnly, - owners: owners, - password: password, - expire: expire + metadata: metadata }); }; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 81ea43d81..72ebec240 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -1074,13 +1074,17 @@ define([ readOnly = false; updateMeta(); - var rtConfig = {}; + var rtConfig = { + metadata: {} + }; if (data.owned) { - rtConfig.owners = [edPublic]; + rtConfig.metadata.owners = [edPublic]; } if (data.expire) { - rtConfig.expire = data.expire; + rtConfig.metadata.expire = data.expire; } + rtConfig.metadata.validateKey = (secret.keys && secret.keys.validateKey) || undefined; + Utils.rtConfig = rtConfig; nThen(function(waitFor) { if (data.templateId) { From 0e843f0beb620372de74710157767ebcdb95e1d0 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 17 Jul 2019 10:32:37 +0200 Subject: [PATCH 02/38] Add upload files in contextmenu --- www/drive/inner.js | 52 ++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/www/drive/inner.js b/www/drive/inner.js index f393cac3f..c615d3a7c 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -87,6 +87,7 @@ define([ var faDelete = 'fa-eraser'; var faProperties = 'fa-database'; var faTags = 'fa-hashtag'; + var faUploadFiles = 'cptools-file-upload'; var faEmpty = 'fa-trash-o'; var faRestore = 'fa-repeat'; var faShowParent = 'fa-location-arrow'; @@ -354,6 +355,11 @@ define([ 'data-icon': faTags, }, Messages.fc_hashtag)), $separator.clone()[0], + h('li', h('a.cp-app-drive-context-uploadfiles.dropdown-item.cp-app-drive-context-editable', { + 'tabindex': '-1', + 'data-icon': faUploadFiles, + }, Messages.uploadButton)), + $separator.clone()[0], h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { 'tabindex': '-1', 'data-icon': AppConfig.applicationsIcon.pad, @@ -977,7 +983,10 @@ define([ // Hide the new shared folder menu if we're already in a shared folder return manager.isInSharedFolder(currentPath) || APP.disableSF; } - return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1; + if (className === 'uploadfiles') { return; } + if (className === 'newdoc') { + return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1; + } }; } else { // In case of multiple selection, we must hide the option if at least one element @@ -1086,7 +1095,7 @@ define([ switch(type) { case 'content': - show = ['newfolder', 'newsharedfolder', 'newdoc']; + show = ['newfolder', 'newsharedfolder', 'uploadfiles', 'newdoc']; break; case 'tree': show = ['open', 'openro', 'expandall', 'collapseall', 'color', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf', 'properties', 'hashtag']; @@ -2099,6 +2108,23 @@ define([ }); return arr; }; + var openUploadFilesModal = function () { + var $input = $('', { + 'type': 'file', + 'style': 'display: none;', + 'multiple': 'multiple' + }).on('change', function (e) { + var files = Util.slice(e.target.files); + files.forEach(function (file) { + var ev = { + target: $content[0], + path: findDropPath($content[0]) + }; + APP.FM.handleFile(file, ev); + }); + }); + $input.click(); + } var addNewPadHandlers = function ($block, isInRoot) { // Handlers if (isInRoot) { @@ -2125,24 +2151,7 @@ define([ }); }); } - $block.find('a.cp-app-drive-new-upload, li.cp-app-drive-new-upload') - .click(function () { - var $input = $('', { - 'type': 'file', - 'style': 'display: none;', - 'multiple': 'multiple' - }).on('change', function (e) { - var files = Util.slice(e.target.files); - files.forEach(function (file) { - var ev = { - target: $content[0], - path: findDropPath($content[0]) - }; - APP.FM.handleFile(file, ev); - }); - }); - $input.click(); - }); + $block.find('a.cp-app-drive-new-upload, li.cp-app-drive-new-upload').click(openUploadFilesModal); } $block.find('a.cp-app-drive-new-doc, li.cp-app-drive-new-doc') .click(function () { @@ -3631,6 +3640,9 @@ define([ manager.addSharedFolder(paths[0].path, obj, refresh); }); } + else if ($(this).hasClass("cp-app-drive-context-uploadfiles")) { + openUploadFilesModal(); + } else if ($(this).hasClass("cp-app-drive-context-newdoc")) { var ntype = $(this).data('type') || 'pad'; var path2 = manager.isPathIn(currentPath, [TRASH]) ? '' : currentPath; From e18433c7f9bd0022ebfe1d3e26a06242f5c1f9ba Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 17 Jul 2019 12:00:22 +0200 Subject: [PATCH 03/38] Add dummy folder upload --- www/common/translations/messages.fr.json | 1 + www/common/translations/messages.json | 1 + www/drive/inner.js | 53 +++++++++++++++++++----- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/www/common/translations/messages.fr.json b/www/common/translations/messages.fr.json index 8d2edb610..3fbeed23e 100644 --- a/www/common/translations/messages.fr.json +++ b/www/common/translations/messages.fr.json @@ -109,6 +109,7 @@ "newButton": "Nouveau", "newButtonTitle": "Créer un nouveau pad", "uploadButton": "Importer des fichiers", + "uploadFolderButton": "Importer un dossier", "uploadButtonTitle": "Importer un nouveau fichier dans le dossier actuel", "saveTemplateButton": "Sauver en tant que modèle", "saveTemplatePrompt": "Choisir un titre pour ce modèle", diff --git a/www/common/translations/messages.json b/www/common/translations/messages.json index 7c5a2ee5b..a45e9a821 100644 --- a/www/common/translations/messages.json +++ b/www/common/translations/messages.json @@ -110,6 +110,7 @@ "newButton": "New", "newButtonTitle": "Create a new pad", "uploadButton": "Upload files", + "uploadFolderButton": "Upload folder", "uploadButtonTitle": "Upload a new file to the current folder", "saveTemplateButton": "Save as template", "saveTemplatePrompt": "Choose a title for the template", diff --git a/www/drive/inner.js b/www/drive/inner.js index c615d3a7c..9b43426ea 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -88,6 +88,7 @@ define([ var faProperties = 'fa-database'; var faTags = 'fa-hashtag'; var faUploadFiles = 'cptools-file-upload'; + var faUploadFolder = 'cptools-folder-upload'; var faEmpty = 'fa-trash-o'; var faRestore = 'fa-repeat'; var faShowParent = 'fa-location-arrow'; @@ -135,6 +136,8 @@ define([ var LS_SEARCHCURSOR = "app-drive-searchCursor"; var FOLDER_CONTENT_ID = "cp-app-drive-content-folder"; + var ALLOW_FOLDERUPLOAD = true; + var config = {}; var DEBUG = config.DEBUG = false; var debug = config.debug = DEBUG ? function () { @@ -359,6 +362,10 @@ define([ 'tabindex': '-1', 'data-icon': faUploadFiles, }, Messages.uploadButton)), + h('li', h('a.cp-app-drive-context-uploadfolder.dropdown-item.cp-app-drive-context-editable', { + 'tabindex': '-1', + 'data-icon': faUploadFolder, + }, Messages.uploadFolderButton)), $separator.clone()[0], h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { 'tabindex': '-1', @@ -984,6 +991,7 @@ define([ return manager.isInSharedFolder(currentPath) || APP.disableSF; } if (className === 'uploadfiles') { return; } + if (className === 'uploadfolder') { return !ALLOW_FOLDERUPLOAD; } if (className === 'newdoc') { return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1; } @@ -1095,7 +1103,7 @@ define([ switch(type) { case 'content': - show = ['newfolder', 'newsharedfolder', 'uploadfiles', 'newdoc']; + show = ['newfolder', 'newsharedfolder', 'uploadfiles', 'uploadfolder', 'newdoc']; break; case 'tree': show = ['open', 'openro', 'expandall', 'collapseall', 'color', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf', 'properties', 'hashtag']; @@ -2108,7 +2116,7 @@ define([ }); return arr; }; - var openUploadFilesModal = function () { + var showUploadFilesModal = function () { var $input = $('', { 'type': 'file', 'style': 'display: none;', @@ -2124,7 +2132,10 @@ define([ }); }); $input.click(); - } + }; + var showUploadFolderModal = function () { + console.log("%cIMPORT FOLDER", "color: red"); + }; var addNewPadHandlers = function ($block, isInRoot) { // Handlers if (isInRoot) { @@ -2151,7 +2162,8 @@ define([ }); }); } - $block.find('a.cp-app-drive-new-upload, li.cp-app-drive-new-upload').click(openUploadFilesModal); + $block.find('a.cp-app-drive-new-fileupload, li.cp-app-drive-new-fileupload').click(showUploadFilesModal); + $block.find('a.cp-app-drive-new-folderupload, li.cp-app-drive-new-folderupload').click(showUploadFolderModal); } $block.find('a.cp-app-drive-new-doc, li.cp-app-drive-new-doc') .click(function () { @@ -2186,9 +2198,16 @@ define([ options.push({tag: 'hr'}); options.push({ tag: 'a', - attributes: {'class': 'cp-app-drive-new-upload'}, + attributes: {'class': 'cp-app-drive-new-fileupload'}, content: $('
').append(getIcon('fileupload')).html() + Messages.uploadButton }); + if (ALLOW_FOLDERUPLOAD) { + options.push({ + tag: 'a', + attributes: {'class': 'cp-app-drive-new-folderupload'}, + content: $('
').append(getIcon('folderupload')).html() + Messages.uploadFolderButton + }); + } options.push({tag: 'hr'}); } getNewPadTypes().forEach(function (type) { @@ -2470,13 +2489,22 @@ define([ $element3.append($('', { 'class': 'cp-app-drive-new-name' }) .text(Messages.fm_sharedFolder)); } - // File - var $element2 = $('
  • ', { - 'class': 'cp-app-drive-new-upload cp-app-drive-element-row ' + - 'cp-app-drive-element-grid' + // Upload file + var $elementFileUpload = $('
  • ', { + 'class': 'cp-app-drive-new-fileupload cp-app-drive-element-row ' + + 'cp-app-drive-element-grid' }).prepend(getIcon('fileupload')).appendTo($container); - $element2.append($('', {'class': 'cp-app-drive-new-name'}) + $elementFileUpload.append($('', {'class': 'cp-app-drive-new-name'}) .text(Messages.uploadButton)); + // Upload folder + if (ALLOW_FOLDERUPLOAD) { + var $elementFolderUpload = $('
  • ', { + 'class': 'cp-app-drive-new-folderupload cp-app-drive-element-row ' + + 'cp-app-drive-element-grid' + }).prepend(getIcon('folderupload')).appendTo($container); + $elementFolderUpload.append($('', {'class': 'cp-app-drive-new-name'}) + .text(Messages.uploadFolderButton)); + } } // Pads getNewPadTypes().forEach(function (type) { @@ -3641,7 +3669,10 @@ define([ }); } else if ($(this).hasClass("cp-app-drive-context-uploadfiles")) { - openUploadFilesModal(); + showUploadFilesModal(); + } + else if ($(this).hasClass("cp-app-drive-context-uploadfolder")) { + showUploadFolderModal(); } else if ($(this).hasClass("cp-app-drive-context-newdoc")) { var ntype = $(this).data('type') || 'pad'; From 1bb47e28efa041cbcb9adb9fc19dbd21e0d63c63 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 17 Jul 2019 10:58:30 +0200 Subject: [PATCH 04/38] Update icons --- .../fonts/cptools/fonts/cptools.svg | 1 + .../fonts/cptools/fonts/cptools.ttf | Bin 5956 -> 6124 bytes .../fonts/cptools/fonts/cptools.woff | Bin 6032 -> 6200 bytes customize.dist/fonts/cptools/style.css | 9 ++++++--- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/customize.dist/fonts/cptools/fonts/cptools.svg b/customize.dist/fonts/cptools/fonts/cptools.svg index f7fe0879f..93eef8d38 100644 --- a/customize.dist/fonts/cptools/fonts/cptools.svg +++ b/customize.dist/fonts/cptools/fonts/cptools.svg @@ -25,4 +25,5 @@ + \ No newline at end of file diff --git a/customize.dist/fonts/cptools/fonts/cptools.ttf b/customize.dist/fonts/cptools/fonts/cptools.ttf index 1dac2ff871a9f8f7fd1f68931e4b34be7d153381..18338a9ee52ce2984e55859361c7740d8b91cac9 100644 GIT binary patch delta 347 zcmX@2_eQ^-fsuiMft#U$ftkU;KUm+0Ux-Z!D6$8L6OwZi3&g`N&17I;lmYTX(i4jd zfV2RR5288Jb1Ktn10A0N`4tQd!bdVv6H`P_WOXtyh}r<<%`$)j?1z|d0Qn_AzDh=J zNktF?TO5!-1IUlb$xn7n)LCYv02KHF6fnq5tSDemX9PM)Oa;hS$V<#k-I=8&4dlB3 zEom#rFD?N(6bQu6faDpNnV(HOV9zKtiP4);XtNKauP{F|gBgPn^C@OO21y1J2AjzZ zEan`H%BITZ;>x0v1z0uMmZW*s)Ob$LV^!4p7jx#?wKL!#0NUwozVc^0zs*+$ZWfRg z3^zk2bHeD!dqm6`#V3CeiC_Urnoaf*)f3`;1lB3e@SlMntbu8=p}6qo`Jzi10kh3b AfdBvi delta 277 zcmaE(e?+gIfsuiMft#U$ftkU;KUm+0Ux-ZsD6$8L6OwZi3&g`N&0t_)lmYTX(i4jd zfV2RR5288Jb1Ks=I;hnE`4tQd!U`Fwi7BG>M*kTYM1Xo2%rbxi?1z}I1Nj$#e3gvc zk_tZtHVq*E3y>d?lb`IEsIyGNj)6hc2PmMIn^;l6pvDMvk|@wn28F!D+|->}TGBxN z9H1p_1^LA#K!*Z>xC%&~ftmT~!~^z>f|D4%83i}{F!~BBgZu-;tKVh%#`D{JW#DE3 msb{#U|J?;fPfiduXB3+}Lo{OY7g0S9pfE_2*k&!ULyQ1GzC5G= diff --git a/customize.dist/fonts/cptools/fonts/cptools.woff b/customize.dist/fonts/cptools/fonts/cptools.woff index 4f01d5d158a831d3f86ed12a0b385ad642835da6..d8f56ba86d4b8da18c3e0b7ccfbf8e9b67c5d96a 100644 GIT binary patch delta 372 zcmbQBzr#SJ+~3WOfsp|SBrF)XLA3ari6YwdO3As21q=*~89=XB3+3!|2T@w0Q=juP{F|&}BxYlyB+av?#&hy6Rzt8jViR?Q>lKo76AKs^7&CwpAs{Rsc4 zVlhZ;50K9R#RBO$m1#h+BMc0}3Lt#ZL9HeuH8F*OLF5TgjTs1w)*JoL017fNh{^!@ zDj>{$i1~U(Zb=1D%mK)c0AW7{HjSM8WS}}f(HTGiJrLGereT+xSOK(H^aPNv0LE&J zjCqNUWvG@%%Pl8Ms-10t^f{^}oBo=*eqD%^AfeKM{?X>>#Em1QZ5o5@Yz!zz Date: Wed, 17 Jul 2019 12:15:14 +0200 Subject: [PATCH 05/38] Add upload-folder icon --- www/common/application_config_internal.js | 1 + www/common/common-interface.js | 1 + www/drive/inner.js | 9 ++++----- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/www/common/application_config_internal.js b/www/common/application_config_internal.js index e4d5aa4f9..6a362b133 100644 --- a/www/common/application_config_internal.js +++ b/www/common/application_config_internal.js @@ -93,6 +93,7 @@ define(function() { config.applicationsIcon = { file: 'cptools-file', fileupload: 'cptools-file-upload', + folderupload: 'cptools-folder-upload', pad: 'cptools-pad', code: 'cptools-code', slide: 'cptools-slide', diff --git a/www/common/common-interface.js b/www/common/common-interface.js index e44a4ecff..6f70d15c3 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -773,6 +773,7 @@ define([ var icon = AppConfig.applicationsIcon[type]; var font = icon.indexOf('cptools') === 0 ? 'cptools' : 'fa'; if (type === 'fileupload') { type = 'file'; } + if (type === 'folderupload') { type = 'file'; } var appClass = ' cp-icon cp-icon-color-'+type; $icon = $('', {'class': font + ' ' + icon + appClass}); } diff --git a/www/drive/inner.js b/www/drive/inner.js index 9b43426ea..61d3ade27 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -45,6 +45,7 @@ define([ editable: false, mobile: function () { return $('body').width() <= 600; }, // Menu and content area are not inline-block anymore for mobiles isMac: navigator.platform === "MacIntel", + allowFolderUpload: true, }; var stringify = function (obj) { @@ -136,8 +137,6 @@ define([ var LS_SEARCHCURSOR = "app-drive-searchCursor"; var FOLDER_CONTENT_ID = "cp-app-drive-content-folder"; - var ALLOW_FOLDERUPLOAD = true; - var config = {}; var DEBUG = config.DEBUG = false; var debug = config.debug = DEBUG ? function () { @@ -991,7 +990,7 @@ define([ return manager.isInSharedFolder(currentPath) || APP.disableSF; } if (className === 'uploadfiles') { return; } - if (className === 'uploadfolder') { return !ALLOW_FOLDERUPLOAD; } + if (className === 'uploadfolder') { return !APP.allowFolderUpload; } if (className === 'newdoc') { return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1; } @@ -2201,7 +2200,7 @@ define([ attributes: {'class': 'cp-app-drive-new-fileupload'}, content: $('
    ').append(getIcon('fileupload')).html() + Messages.uploadButton }); - if (ALLOW_FOLDERUPLOAD) { + if (APP.allowFolderUpload) { options.push({ tag: 'a', attributes: {'class': 'cp-app-drive-new-folderupload'}, @@ -2497,7 +2496,7 @@ define([ $elementFileUpload.append($('', {'class': 'cp-app-drive-new-name'}) .text(Messages.uploadButton)); // Upload folder - if (ALLOW_FOLDERUPLOAD) { + if (APP.allowFolderUpload) { var $elementFolderUpload = $('
  • ', { 'class': 'cp-app-drive-new-folderupload cp-app-drive-element-row ' + 'cp-app-drive-element-grid' From adef61672c55a59d386dbe9053a54561cee68013 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 17 Jul 2019 17:00:43 +0200 Subject: [PATCH 06/38] Fix translation key --- www/common/notifications.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/www/common/notifications.js b/www/common/notifications.js index 7ab504fb6..7a90b2e0c 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -126,17 +126,18 @@ define([ var link = h('a', { href: '#' }, Messages.requestEdit_viewPad); - var verified = h('p.cp-notifications-requestedit-verified'); + var verified = h('p'); var $verified = $(verified); if (priv.friends && priv.friends[msg.author]) { + $verified.addClass('cp-notifications-requestedit-verified'); var f = priv.friends[msg.author]; $verified.append(h('span.fa.fa-certificate')); var $avatar = $(h('span.cp-avatar')).appendTo($verified); $verified.append(h('p', Messages._getKey('requestEdit_fromFriend', [f.displayName]))); common.displayAvatar($avatar, f.avatar, f.displayName); } else { - $verified.append(Messages.requestEdit_fromStranger); + $verified.append(Messages._getKey('requestEdit_fromStranger', [msg.content.user.displayName])); } var div = h('div', [ From 51facff6fde1d6f93ef19aa74a62ae4dd420474f Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 17 Jul 2019 17:01:25 +0200 Subject: [PATCH 07/38] Send a mailbox address (encrypted) to the owned pads metadata --- www/common/cryptpad-common.js | 4 ++ www/common/outer/async-store.js | 70 +++++++++++++++++++++---------- www/common/outer/store-rpc.js | 1 + www/common/sframe-common-outer.js | 39 ++++++++++++++--- www/common/toolbar3.js | 1 - 5 files changed, 86 insertions(+), 29 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 0311387ee..4ffbd4c0c 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -700,6 +700,10 @@ define([ postMessage("GIVE_PAD_ACCESS", data, cb); }; + common.getPadMetadata = function (data, cb) { + postMessage('GET_PAD_METADATA', data, cb); + }; + common.changePadPassword = function (Crypt, href, newPassword, edPublic, cb) { if (!href) { return void cb({ error: 'EINVAL_HREF' }); } var parsed = Hash.parsePadUrl(href); diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 063d23ad8..417fd0fa8 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1242,10 +1242,9 @@ define([ }; Store.requestPadAccess = function (clientId, data, cb) { - // Get owners from pad metadata - // Try to find an owner in our friend list - // Mailbox... + var owner = data.owner; var channel = channels[data.channel]; + if (!channel) { return void cb({error: 'ENOTFOUND'}); } if (!data.send && channel && (!channel.data || !channel.data.channel)) { var i = 0; var it = setInterval(function () { @@ -1261,11 +1260,12 @@ define([ }, 200); return; } + + // If the owner was not is the pad metadata, check if it is a friend var fData = channel.data || {}; - if (fData.owners) { + if (!owner && fData.owners) { var friends = store.proxy.friends || {}; if (Object.keys(friends).length > 1) { - var owner; fData.owners.some(function (edPublic) { return Object.keys(friends).some(function (curve) { if (curve === "me") { return; } @@ -1276,26 +1276,28 @@ define([ } }); }); - if (owner) { - if (data.send) { - var myData = Messaging.createData(store.proxy); - delete myData.channel; - store.mailbox.sendTo('REQUEST_PAD_ACCESS', { - channel: data.channel, - user: myData - }, { - channel: owner.notifications, - curvePublic: owner.curvePublic - }, function () { - cb({state: true}); - }); - return; - } - return void cb({state: true}); - } } } - cb({sent: false}); + + // If send is true, send the request to the owner. + if (owner) { + if (data.send) { + var myData = Messaging.createData(store.proxy); + delete myData.channel; + store.mailbox.sendTo('REQUEST_PAD_ACCESS', { + channel: data.channel, + user: myData + }, { + channel: owner.notifications, + curvePublic: owner.curvePublic + }, function () { + cb({state: true}); + }); + return; + } + return void cb({state: true}); + } + cb({state: false}); }; Store.givePadAccess = function (clientId, data, cb) { var edPublic = store.proxy.edPublic; @@ -1332,6 +1334,28 @@ define([ cb(); }; + Store.getPadMetadata = function (clientId, data, cb) { + if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); } + var channel = channels[data.channel]; + if (!channel) { return void cb({ error: 'ENOTFOUND' }); } + if (!channel.data || !channel.data.channel) { + var i = 0; + var it = setInterval(function () { + if (channel.data && channel.data.channel) { + clearInterval(it); + Store.getPadMetadata(clientId, data, cb); + return; + } + if (i >= 300) { // One minute timeout + clearInterval(it); + } + i++; + }, 200); + return; + } + cb(channel.data || {}); + }; + // GET_FULL_HISTORY from sframe-common-outer Store.getFullHistory = function (clientId, data, cb) { var network = store.network; diff --git a/www/common/outer/store-rpc.js b/www/common/outer/store-rpc.js index bb8e0a674..18096d96d 100644 --- a/www/common/outer/store-rpc.js +++ b/www/common/outer/store-rpc.js @@ -80,6 +80,7 @@ define([ IS_NEW_CHANNEL: Store.isNewChannel, REQUEST_PAD_ACCESS: Store.requestPadAccess, GIVE_PAD_ACCESS: Store.givePadAccess, + GET_PAD_METADATA: Store.getPadMetadata, // Drive DRIVE_USEROBJECT: Store.userObjectCommand, // Settings, diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 72ebec240..eff90150c 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -272,7 +272,7 @@ define([ var parsed = Utils.Hash.parsePadUrl(window.location.href); if (!parsed.type) { throw new Error(); } var defaultTitle = Utils.Hash.getDefaultName(parsed); - var edPublic; + var edPublic, curvePublic, notifications; var forceCreationScreen = cfg.useCreationScreen && sessionStorage[Utils.Constants.displayPadCreationScreen]; delete sessionStorage[Utils.Constants.displayPadCreationScreen]; @@ -284,6 +284,8 @@ define([ if (err) { console.log(err); } metaObj = m; edPublic = metaObj.priv.edPublic; // needed to create an owned pad + curvePublic = metaObj.user.curvePublic; + notifications = metaObj.user.notifications; })); Cryptpad.isTemplate(window.location.href, waitFor(function (err, t) { if (err) { console.log(err); } @@ -948,10 +950,33 @@ define([ if (readOnly && hashes.editHash) { return void cb({error: 'ALREADYKNOWN'}); } - Cryptpad.padRpc.requestAccess({ - send: data, - channel: secret.channel - }, cb); + var owner; + var crypto = Crypto.createEncryptor(secret.keys); + nThen(function (waitFor) { + // Try to get the owner's mailbox from the pad metadata first. + // If it's is an older owned pad, check if the owner is a friend + // or an acquaintance (from async-store directly in requestAccess) + Cryptpad.getPadMetadata({ + channel: secret.channel + }, waitFor(function (obj) { + obj = obj || {}; + if (obj.error) { return; } + if (obj.mailbox) { + try { + var dataStr = crypto.decrypt(obj.mailbox, true, true); + var data = JSON.parse(dataStr); + if (!data.notifications || !data.curvePublic) { return; } + owner = data; + } catch (e) { console.error(e); } + } + })); + }).nThen(function () { + Cryptpad.padRpc.requestAccess({ + send: data, + channel: secret.channel, + owner: owner + }, cb); + }); }); if (cfg.messaging) { @@ -1079,6 +1104,10 @@ define([ }; if (data.owned) { rtConfig.metadata.owners = [edPublic]; + rtConfig.metadata.mailbox = Utils.crypto.encrypt(JSON.stringify({ + notifications: notifications, + curvePublic: curvePublic + })); } if (data.expire) { rtConfig.metadata.expire = data.expire; diff --git a/www/common/toolbar3.js b/www/common/toolbar3.js index 6c262e2d1..a2547d223 100644 --- a/www/common/toolbar3.js +++ b/www/common/toolbar3.js @@ -575,7 +575,6 @@ MessengerUI, Messages) { }; var createRequest = function (toolbar, config) { - console.error('test'); if (!config.metadataMgr) { throw new Error("You must provide a `metadataMgr` to display the request access button"); } From a5310e323a4d95714198e30b4ca3c6f5f268a07d Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 17 Jul 2019 18:02:25 +0200 Subject: [PATCH 08/38] Almost functionnal folder import --- www/drive/inner.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/www/drive/inner.js b/www/drive/inner.js index 61d3ade27..c1d05d4ab 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -2132,8 +2132,89 @@ define([ }); $input.click(); }; + + // create the folder structure before to upload files from folder + var uploadFolder = function (fileList) { + var currentFolder = currentPath; + // create an array of all the files relative path + var files = Array.prototype.map.call(fileList, function (file) { + return { + file: file, + path: file.webkitRelativePath.split("/"), + }; + }); + // if folder name already exist in drive, rename it + var uploadedFolderName = files[0].path[0]; + var availableName = manager.user.userObject.getAvailableName(manager.user.userObject.find(currentFolder), uploadedFolderName); + if (uploadedFolderName !== availableName) { + files.forEach(function (file) { + file.path[0] = availableName; + }); + } + + // uploadSteps is an array of objects {folders: [], files: []}, containing all the folders and files to create safely + // at the index i + 1, the files and folders are children of the folders at the index i + var maxSteps = files.reduce(function (max, file) { return Math.max(max, file.path.length); }, 0); + console.log("maxSteps", maxSteps); + var uploadSteps = [] + for (var i = 0 ; i < maxSteps ; i++) { + uploadSteps[i] = { + folders: [], + files: [], + }; + } + files.forEach(function (file) { + // add steps for subfolders containing file + for (var depth = 0 ; depth < file.path.length - 1 ; depth++) { + var subfolderStr = file.path.slice(0, depth + 1).join("/"); + if (uploadSteps[depth].folders.indexOf(subfolderStr) === -1) { + uploadSteps[depth].folders.push(subfolderStr); + } + }; + // add step for file (one step later than the step for its direct parent folder) + uploadSteps[file.path.length - 1].files.push(file); + }); + console.log(uploadSteps); + + // add folders, then add files when theirs folders have been created + // wait for the folders to be created to go to the next step (don't wait for the files) + var stepByStep = function (uploadSteps, i) { + if (i >= uploadSteps.length) { return; } + nThen(function (waitFor) { + // add folders + uploadSteps[i].folders.forEach(function (folder) { + var folderPath = folder.split("/"); + var parentFolder = currentFolder.concat(folderPath.slice(0, -1)); + var folderName = folderPath.slice(-1); + manager.addFolder(parentFolder, folderName, waitFor(refresh)); + }); + // upload files + uploadSteps[i].files.forEach(function (file) { + var ev = { + target: $content[0], + path: file.path, + }; + console.log(file); + console.log(ev); +// APP.FM.handleFile(file.file, ev); // THIS LINE NEED TO BE FIXED + }); + }).nThen(function () { + stepByStep(uploadSteps, i + 1); + }); + } + stepByStep(uploadSteps, 0); + }; var showUploadFolderModal = function () { console.log("%cIMPORT FOLDER", "color: red"); + var $input = $('', { + 'type': 'file', + 'style': 'display: none;', + 'multiple': 'multiple', + 'webkitdirectory': true, + }).on('change', function (e) { + uploadFolder(e.target.files); + }); + $input.click(); }; var addNewPadHandlers = function ($block, isInRoot) { // Handlers From 73dcce564e2ea7116e266d91aec1186882aeee96 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 11:38:33 +0200 Subject: [PATCH 09/38] Functionnal folder upload --- www/drive/inner.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/www/drive/inner.js b/www/drive/inner.js index c1d05d4ab..e37cc09a0 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -2145,7 +2145,7 @@ define([ }); // if folder name already exist in drive, rename it var uploadedFolderName = files[0].path[0]; - var availableName = manager.user.userObject.getAvailableName(manager.user.userObject.find(currentFolder), uploadedFolderName); + var availableName = manager.user.userObject.getAvailableName(manager.find(currentFolder), uploadedFolderName); if (uploadedFolderName !== availableName) { files.forEach(function (file) { file.path[0] = availableName; @@ -2155,8 +2155,7 @@ define([ // uploadSteps is an array of objects {folders: [], files: []}, containing all the folders and files to create safely // at the index i + 1, the files and folders are children of the folders at the index i var maxSteps = files.reduce(function (max, file) { return Math.max(max, file.path.length); }, 0); - console.log("maxSteps", maxSteps); - var uploadSteps = [] + var uploadSteps = []; for (var i = 0 ; i < maxSteps ; i++) { uploadSteps[i] = { folders: [], @@ -2170,7 +2169,7 @@ define([ if (uploadSteps[depth].folders.indexOf(subfolderStr) === -1) { uploadSteps[depth].folders.push(subfolderStr); } - }; + } // add step for file (one step later than the step for its direct parent folder) uploadSteps[file.path.length - 1].files.push(file); }); @@ -2192,16 +2191,14 @@ define([ uploadSteps[i].files.forEach(function (file) { var ev = { target: $content[0], - path: file.path, + path: currentFolder.concat(file.path.slice(0, -1)), }; - console.log(file); - console.log(ev); -// APP.FM.handleFile(file.file, ev); // THIS LINE NEED TO BE FIXED + APP.FM.handleFile(file.file, ev); }); }).nThen(function () { stepByStep(uploadSteps, i + 1); }); - } + }; stepByStep(uploadSteps, 0); }; var showUploadFolderModal = function () { From 1361334eaf19bad918f4dfd71b253f0309214771 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 11:43:14 +0200 Subject: [PATCH 10/38] Fix file name & extension in upload options --- www/common/sframe-common-file.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 099176afd..8358b7054 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -235,9 +235,9 @@ define([ store: true }; var fileUploadModal = function (file, cb) { - var extIdx = file.name.lastIndexOf('.'); - var name = extIdx !== -1 ? file.name.slice(0,extIdx) : file.name; - var ext = extIdx !== -1 ? file.name.slice(extIdx) : ""; + var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(file.name) || []; + var name = parsedName[1] || file.name; + var ext = parsedName[2] || ""; var createHelper = function (href, text) { var q = h('a.fa.fa-question-circle', { @@ -264,7 +264,7 @@ define([ h('h4', Messages.upload_modal_title), UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages._getKey('upload_modal_filename', [ext])), - h('input#cp-upload-name', {type: 'text', placeholder: name}), + h('input#cp-upload-name', {type: 'text', placeholder: name, value: name}), h('label', {for: 'cp-upload-password'}, Messages.creation_passwordValue), UI.passwordInput({id: 'cp-upload-password'}), h('span', { From 06cbabd3735a965abac320c77f368a16fbf31798 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 12:15:20 +0200 Subject: [PATCH 11/38] Add extension in file name in upload options --- www/common/sframe-common-file.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 8358b7054..d72db01c6 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -264,7 +264,7 @@ define([ h('h4', Messages.upload_modal_title), UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages._getKey('upload_modal_filename', [ext])), - h('input#cp-upload-name', {type: 'text', placeholder: name, value: name}), + h('input#cp-upload-name', {type: 'text', placeholder: file.name, value: file.name}), h('label', {for: 'cp-upload-password'}, Messages.creation_passwordValue), UI.passwordInput({id: 'cp-upload-password'}), h('span', { From 165feef7d4037ec267af3bc8d894c9bc7a945f81 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 15:22:09 +0200 Subject: [PATCH 12/38] Folder upload only shows a modal for global folder options --- www/common/sframe-common-file.js | 128 +++++++++++++++++++++++-------- www/drive/inner.js | 106 +++++++++++++------------ 2 files changed, 154 insertions(+), 80 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index d72db01c6..7605ad85d 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -234,37 +234,40 @@ define([ owned: true, store: true }; - var fileUploadModal = function (file, cb) { - var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(file.name) || []; - var name = parsedName[1] || file.name; - var ext = parsedName[2] || ""; - - var createHelper = function (href, text) { - var q = h('a.fa.fa-question-circle', { - style: 'text-decoration: none !important;', - title: text, - href: origin + href, - target: "_blank", - 'data-tippy-placement': "right" - }); - return q; - }; - + var createHelper = function (href, text) { + var q = h('a.fa.fa-question-circle', { + style: 'text-decoration: none !important;', + title: text, + href: origin + href, + target: "_blank", + 'data-tippy-placement': "right" + }); + return q; + }; + var createManualStore = function (isFolderUpload) { var privateData = common.getMetadataMgr().getPrivateData(); var autoStore = Util.find(privateData, ['settings', 'general', 'autostore']) || 0; var initialState = modalState.owned || modalState.store; var initialDisabled = modalState.owned ? { disabled: true } : {}; var manualStore = autoStore === 1 ? undefined : - UI.createCheckbox('cp-upload-store', Messages.autostore_forceSave, initialState, { - input: initialDisabled - }); + UI.createCheckbox('cp-upload-store', isFolderUpload ? (Messages.uploadFolder_modal_forceSave || "Store files in your cryptDrive") : Messages.autostore_forceSave, initialState, { + input: initialDisabled + }); + return manualStore; + } + var fileUploadModal = function (defaultFileName, cb) { + var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(defaultFileName) || []; + var name = parsedName[1] || defaultFileName; + var ext = parsedName[2] || ""; + + var manualStore = createManualStore(); // Ask for name, password and owner var content = h('div', [ h('h4', Messages.upload_modal_title), UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages._getKey('upload_modal_filename', [ext])), - h('input#cp-upload-name', {type: 'text', placeholder: file.name, value: file.name}), + h('input#cp-upload-name', {type: 'text', placeholder: defaultFileName, value: defaultFileName}), h('label', {for: 'cp-upload-password'}, Messages.creation_passwordValue), UI.passwordInput({id: 'cp-upload-password'}), h('span', { @@ -298,7 +301,7 @@ define([ modalState.store = forceSave; // Add extension to the name if needed - if (!newName || !newName.trim()) { newName = file.name; } + if (!newName || !newName.trim()) { newName = defaultFileName; } var newExtIdx = newName.lastIndexOf('.'); var newExt = newExtIdx !== -1 ? newName.slice(newExtIdx) : ""; if (newExt !== ext) { newName += ext; } @@ -312,12 +315,64 @@ define([ }); }; + var showFolderUploadModal = File.showFolderUploadModal = function (foldername, cb) { + var manualStore = createManualStore(); + + // Ask for name, password and owner + var content = h('div', [ + h('h4', Messages.uploadFolder_modal_title || "Folder upload options"), + UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages.fm_folderName), + h('input#cp-upload-foldername', {type: 'text', placeholder: foldername, value: foldername}), + h('label', {for: 'cp-upload-password'}, Messages.uploadFolder_modal_filesPassword || "Files password"), + UI.passwordInput({id: 'cp-upload-password'}), + h('span', { + style: 'display:flex;align-items:center;justify-content:space-between' + }, [ + UI.createCheckbox('cp-upload-owned', Messages.uploadFolder_modal_owner || "Owned files", modalState.owned), + createHelper('/faq.html#keywords-owned', Messages.creation_owned1) + ]), + manualStore + ]); + + $(content).find('#cp-upload-owned').on('change', function () { + var val = $(content).find('#cp-upload-owned').is(':checked'); + if (val) { + $(content).find('#cp-upload-store').prop('checked', true).prop('disabled', true); + } else { + $(content).find('#cp-upload-store').prop('disabled', false); + } + }); + + UI.confirm(content, function (yes) { + if (!yes) { return void cb(); } + + // Get the values + var newName = $(content).find('#cp-upload-foldername').val(); + var password = $(content).find('#cp-upload-password').val() || undefined; + var owned = $(content).find('#cp-upload-owned').is(':checked'); + var forceSave = owned || $(content).find('#cp-upload-store').is(':checked'); + + modalState.owned = owned; + modalState.store = forceSave; + + if (!newName || !newName.trim()) { newName = foldername; } + + cb({ + folderName: newName, + password: password, + owned: owned, + forceSave: forceSave + }); + }); + } + var handleFileState = { queue: [], inProgress: false }; - var handleFile = File.handleFile = function (file, e) { - if (handleFileState.inProgress) { return void handleFileState.queue.push([file, e]); } + /* if defaultOptions is passed, the function does not show the upload options modal, and directly save the file with the specified options */ + var handleFile = File.handleFile = function (file, e, defaultOptions) { + if (handleFileState.inProgress) { return void handleFileState.queue.push([file, e, defaultOptions]); } handleFileState.inProgress = true; var thumb; @@ -345,7 +400,7 @@ define([ handleFileState.inProgress = false; if (handleFileState.queue.length) { var next = handleFileState.queue.shift(); - handleFile(next[0], next[1]); + handleFile(next[0], next[1], next[2]); } }; var getName = function () { @@ -354,14 +409,25 @@ define([ if (config.noStore) { return void finish(); } // Otherwise, ask for password, name and ownership - fileUploadModal(file, function (obj) { - if (!obj) { return void finish(true); } - name = obj.name; - password = obj.password; - owned = obj.owned; - forceSave = obj.forceSave; + // if default options were passed, upload file immediately + if (defaultOptions && typeof defaultOptions === "object") { + name = defaultOptions.name || file.name; + password = defaultOptions.password || undefined; + owned = defaultOptions.owned || true; + forceSave = defaultOptions.forceSave || true; finish(); - }); + } + // if no default options were passed, ask the user + else { + fileUploadModal(file.name, function (obj) { + if (!obj) { return void finish(true); } + name = obj.name; + password = obj.password; + owned = obj.owned; + forceSave = obj.forceSave; + finish(); + }); + } }; blobToArrayBuffer(file, function (e, buffer) { diff --git a/www/drive/inner.js b/www/drive/inner.js index e37cc09a0..2018df703 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -2146,60 +2146,68 @@ define([ // if folder name already exist in drive, rename it var uploadedFolderName = files[0].path[0]; var availableName = manager.user.userObject.getAvailableName(manager.find(currentFolder), uploadedFolderName); - if (uploadedFolderName !== availableName) { + + // ask for folder name and files options, then upload all the files! + APP.FM.showFolderUploadModal(availableName, function (folderUploadOptions) { + if (!folderUploadOptions) { return; } + + // verfify folder name is possible, and update files path + availableName = manager.user.userObject.getAvailableName(manager.find(currentFolder), folderUploadOptions.folderName); + if (uploadedFolderName !== availableName) { + files.forEach(function (file) { + file.path[0] = availableName; + }); + } + + // uploadSteps is an array of objects {folders: [], files: []}, containing all the folders and files to create safely + // at the index i + 1, the files and folders are children of the folders at the index i + var maxSteps = files.reduce(function (max, file) { return Math.max(max, file.path.length); }, 0); + var uploadSteps = []; + for (var i = 0 ; i < maxSteps ; i++) { + uploadSteps[i] = { + folders: [], + files: [], + }; + } files.forEach(function (file) { - file.path[0] = availableName; + // add steps to create subfolders containing file + for (var depth = 0 ; depth < file.path.length - 1 ; depth++) { + var subfolderStr = file.path.slice(0, depth + 1).join("/"); + if (uploadSteps[depth].folders.indexOf(subfolderStr) === -1) { + uploadSteps[depth].folders.push(subfolderStr); + } + } + // add step to upload file (one step later than the step of its direct parent folder) + uploadSteps[file.path.length - 1].files.push(file); }); - } - // uploadSteps is an array of objects {folders: [], files: []}, containing all the folders and files to create safely - // at the index i + 1, the files and folders are children of the folders at the index i - var maxSteps = files.reduce(function (max, file) { return Math.max(max, file.path.length); }, 0); - var uploadSteps = []; - for (var i = 0 ; i < maxSteps ; i++) { - uploadSteps[i] = { - folders: [], - files: [], + // add folders, then add files when theirs folders have been created + // wait for the folders to be created to go to the next step (don't wait for the files) + var stepByStep = function (uploadSteps, i) { + if (i >= uploadSteps.length) { return; } + nThen(function (waitFor) { + // add folders + uploadSteps[i].folders.forEach(function (folder) { + var folderPath = folder.split("/"); + var parentFolder = currentFolder.concat(folderPath.slice(0, -1)); + var folderName = folderPath.slice(-1); + manager.addFolder(parentFolder, folderName, waitFor(refresh)); + }); + // upload files + uploadSteps[i].files.forEach(function (file) { + var ev = { + target: $content[0], + path: currentFolder.concat(file.path.slice(0, -1)), + }; + APP.FM.handleFile(file.file, ev, folderUploadOptions); + }); + }).nThen(function () { + stepByStep(uploadSteps, i + 1); + }); }; - } - files.forEach(function (file) { - // add steps for subfolders containing file - for (var depth = 0 ; depth < file.path.length - 1 ; depth++) { - var subfolderStr = file.path.slice(0, depth + 1).join("/"); - if (uploadSteps[depth].folders.indexOf(subfolderStr) === -1) { - uploadSteps[depth].folders.push(subfolderStr); - } - } - // add step for file (one step later than the step for its direct parent folder) - uploadSteps[file.path.length - 1].files.push(file); + + stepByStep(uploadSteps, 0); }); - console.log(uploadSteps); - - // add folders, then add files when theirs folders have been created - // wait for the folders to be created to go to the next step (don't wait for the files) - var stepByStep = function (uploadSteps, i) { - if (i >= uploadSteps.length) { return; } - nThen(function (waitFor) { - // add folders - uploadSteps[i].folders.forEach(function (folder) { - var folderPath = folder.split("/"); - var parentFolder = currentFolder.concat(folderPath.slice(0, -1)); - var folderName = folderPath.slice(-1); - manager.addFolder(parentFolder, folderName, waitFor(refresh)); - }); - // upload files - uploadSteps[i].files.forEach(function (file) { - var ev = { - target: $content[0], - path: currentFolder.concat(file.path.slice(0, -1)), - }; - APP.FM.handleFile(file.file, ev); - }); - }).nThen(function () { - stepByStep(uploadSteps, i + 1); - }); - }; - stepByStep(uploadSteps, 0); }; var showUploadFolderModal = function () { console.log("%cIMPORT FOLDER", "color: red"); From 5c5a6b963d22b8c2c8346b928af3e0540a4e1be1 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 16:07:14 +0200 Subject: [PATCH 13/38] Fix defaults options for folder upload --- www/common/sframe-common-file.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 7605ad85d..9af9ab18a 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -413,8 +413,8 @@ define([ if (defaultOptions && typeof defaultOptions === "object") { name = defaultOptions.name || file.name; password = defaultOptions.password || undefined; - owned = defaultOptions.owned || true; - forceSave = defaultOptions.forceSave || true; + owned = !!defaultOptions.owned; + forceSave = !!defaultOptions.forceSave; finish(); } // if no default options were passed, ask the user From 438ff211e1cb4c7defd97a106197d79d7eda6085 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 16:11:19 +0200 Subject: [PATCH 14/38] Add condition to allow folder upload --- www/drive/inner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/drive/inner.js b/www/drive/inner.js index 2018df703..bf01942f4 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -45,7 +45,7 @@ define([ editable: false, mobile: function () { return $('body').width() <= 600; }, // Menu and content area are not inline-block anymore for mobiles isMac: navigator.platform === "MacIntel", - allowFolderUpload: true, + allowFolderUpload: File.prototype.hasOwnProperty("webkitRelativePath"), }; var stringify = function (obj) { From b49c39b895890d8277f0cc70106dc9db9c3b111a Mon Sep 17 00:00:00 2001 From: ClemDee Date: Fri, 19 Jul 2019 11:34:30 +0200 Subject: [PATCH 15/38] Fix file progress value going over 100% --- www/common/outer/upload.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/common/outer/upload.js b/www/common/outer/upload.js index cd0f9b134..9cb19f18b 100644 --- a/www/common/outer/upload.js +++ b/www/common/outer/upload.js @@ -65,6 +65,7 @@ define([ if (box) { actual += box.length; var progressValue = (actual / estimate * 100); + progressValue = Math.min(progressValue, 100); updateProgress(progressValue); return void sendChunk(box, function (e) { From b74f7b5ec2d68320ebf2c24ba2daa0d6141aa5c5 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Fri, 19 Jul 2019 11:36:43 +0200 Subject: [PATCH 16/38] Set file upload progressbar responsive --- www/common/sframe-common-file.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 9af9ab18a..f400511a1 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -106,10 +106,14 @@ define([ var $pc = $row.find('.cp-fileupload-table-progress'); var $link = $row.find('.cp-fileupload-table-link'); + /** + * Update progress in the download panel, for uploading a file + * @param {number} progressValue Progression of download, between 0 and 100 + */ updateProgress = function (progressValue) { - $pv.text(Math.round(progressValue*100)/100 + '%'); + $pv.text(Math.round(progressValue * 100) / 100 + '%'); $pb.css({ - width: (progressValue/100)*$pc.width()+'px' + width: progressValue + '%' }); }; @@ -537,20 +541,28 @@ define([ queue.next(); }; + /** + * Update progress in the download panel, for downloading a file + * @param {number} progressValue Progression of download, between 0 and 1 + */ var updateDLProgress = function (progressValue) { - var text = Math.round(progressValue*100) + '%'; - text += ' ('+ Messages.download_step1 +'...)'; + var text = Math.round(progressValue * 100) + '%'; + text += ' ('+ Messages.download_step1 + '...)'; $pv.text(text); $pb.css({ - width: progressValue * $pc.width()+'px' + width: (progressValue * 100) + '%' }); }; + /** + * Update progress in the download panel, for decrypting a file (after downloading it) + * @param {number} progressValue Progression of download, between 0 and 1 + */ var updateProgress = function (progressValue) { - var text = Math.round(progressValue*100) + '%'; - text += progressValue === 1 ? '' : ' ('+ Messages.download_step2 +'...)'; + var text = Math.round(progressValue * 100) + '%'; + text += progressValue === 1 ? '' : ' (' + Messages.download_step2 + '...)'; $pv.text(text); $pb.css({ - width: progressValue * $pc.width()+'px' + width: (progressValue * 100) + '%' }); }; From e542be75a3ac8186b42c41bdffa7a3144422e887 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Fri, 19 Jul 2019 11:37:50 +0200 Subject: [PATCH 17/38] Don't hide download panel if mouse over --- www/common/sframe-common-file.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index f400511a1..ef537811b 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -183,8 +183,14 @@ define([ clearTimeout(queue.to); queue.to = window.setTimeout(function () { if (config.keepTable) { return; } - File.$container.fadeOut(); - }, 3000); + // don't hide panel if mouse over + if (File.$container.is(":hover")) { + File.$container.one("mouseleave", function () { File.$container.fadeOut(); }); + } + else { + File.$container.fadeOut(); + } + }, 20000); return; } if (queue.inProgress) { return; } From ef95da707ed8988c04425fd31f5a2335a19cf21c Mon Sep 17 00:00:00 2001 From: ClemDee Date: Mon, 29 Jul 2019 11:22:52 +0200 Subject: [PATCH 18/38] Modify upload panel style --- .../src/less2/include/fileupload.less | 78 ++++++++++++++----- www/common/sframe-common-file.js | 69 +++++++++------- 2 files changed, 102 insertions(+), 45 deletions(-) diff --git a/customize.dist/src/less2/include/fileupload.less b/customize.dist/src/less2/include/fileupload.less index e993d3030..8871eb6af 100644 --- a/customize.dist/src/less2/include/fileupload.less +++ b/customize.dist/src/less2/include/fileupload.less @@ -1,3 +1,4 @@ +@import (reference) "./browser.less"; @import (reference) './colortheme-all.less'; @import (reference) './modal.less'; @@ -10,24 +11,35 @@ #cp-fileupload { .modal_base(); position: absolute; - left: 10vw; right: 10vw; + right: 10vw; bottom: 10vh; - opacity: 0.9; box-sizing: border-box; z-index: 1000000; //Z file upload table container display: none; - #cp-fileupload-table { - width: 80vw; - tr:nth-child(1) { - background-color: darken(@colortheme_modal-bg, 20%); - td { - font-weight: bold; - padding: 0.25em; - &:nth-child(4), &:nth-child(5) { - text-align: center; - } + color: darken(@colortheme_drive-bg, 10%); + + @media screen and (max-width: @browser_media-medium-screen) { + left: 5vw; right: 5vw; bottom: 5vw; + } + + .cp-fileupload-header { + display: flex; + background-color: darken(@colortheme_modal-bg, 10%); + font-weight: bold; + .cp-fileupload-header-title { + padding: 0.25em 0.5em; + flex-grow: 1; + } + .cp-fileupload-header-close { + padding: 0.25em 0.5em; + cursor: pointer; + &:hover { + background-color: rgba(0,0,0,0.1); } } + } + #cp-fileupload-table { + width: 100%; @upload_pad_h: 0.25em; @upload_pad_v: 0.5em; @@ -35,27 +47,55 @@ padding: @upload_pad_h @upload_pad_v; } .cp-fileupload-table-link { + display: flex; + align-items: center; + white-space: nowrap; + max-width: 30vw; + margin: 0px @upload_pad_v; .fa { + margin-top: 4px; margin-right: 5px; } + .cp-fileupload-table-name { + overflow: hidden; + text-overflow: ellipsis; + } + &[href]:hover { + text-decoration: none; + .cp-fileupload-table-name { + text-decoration: underline; + } + } } .cp-fileupload-table-progress { - width: 25%; + min-width: 8em; + max-width: 16em; position: relative; text-align: center; box-sizing: border-box; } .cp-fileupload-table-progress-container { + position: relative; + } + .cp-fileupload-table-progressbar { position: absolute; width: 0px; - left: @upload_pad_v; - top: @upload_pad_h; bottom: @upload_pad_h; - background-color: rgba(0,0,255,0.3); + height: 100%; + background-color: #dddddd; z-index: -1; //Z file upload progress container } - .cp-fileupload-table-cancel { text-align: center; } - .fa.cancel { - color: rgb(255, 0, 115); + .cp-fileupload-table-cancel { + text-align: center; + padding: 0px; + &:not(.success):not(.cancelled):hover { + background-color: rgba(0,0,0,0.1); + } + .fa { + padding: @upload_pad_h @upload_pad_v; + &.fa-times { + cursor: pointer; + } + } } } } diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index ef537811b..8f71d281b 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -42,16 +42,19 @@ define([ return 'cp-fileupload-element-' + String(Math.random()).substring(2); }; + var tableHeader = h('div.cp-fileupload-header', [ + h('div.cp-fileupload-header-title', h('span', Messages.fileuploadHeader || 'Uploaded files')), + h('div.cp-fileupload-header-close', h('span.fa.fa-times')), + ]); + + var $table = File.$table = $('', { id: 'cp-fileupload-table' }); - var $thead = $('').appendTo($table); - $('', {id: id}).appendTo($table); var $lines = $table.find('tr[id]'); @@ -221,19 +224,28 @@ define([ var $cancel = $('', {'class': 'cp-fileupload-table-cancel-button fa fa-times'}).click(function () { queue.queue = queue.queue.filter(function (el) { return el.id !== id; }); $cancel.remove(); - $tr.find('.cp-fileupload-table-cancel').text('-'); + $tr.find('.cp-fileupload-table-cancel').addClass('cancelled').html('').append(h('span.fa.fa-minus')); $tr.find('.cp-fileupload-table-progress-value').text(Messages.upload_cancelled); }); var $link = $('', { 'class': 'cp-fileupload-table-link', 'rel': 'noopener noreferrer' - }).text(obj.dl ? obj.name : obj.metadata.name); + }).append(h('span.cp-fileupload-table-name', obj.dl ? obj.name : obj.metadata.name)); - $('
    ').text(Messages.upload_type).appendTo($thead); - $('').text(Messages.upload_name).appendTo($thead); - $('').text(Messages.upload_size).appendTo($thead); - $('').text(Messages.upload_progress).appendTo($thead); - $('').text(Messages.cancel).appendTo($thead); var createTableContainer = function ($body) { - File.$container = $('
    ', { id: 'cp-fileupload' }).append($table).appendTo($body); + File.$container = $('
    ', { id: 'cp-fileupload' }).append(tableHeader).append($table).appendTo($body); + $('.cp-fileupload-header-close').click(function () { + File.$container.fadeOut(); + }); return File.$container; }; @@ -100,10 +103,9 @@ define([ var $row = $table.find('tr[id="'+id+'"]'); - $row.find('.cp-fileupload-table-cancel').html('-'); + $row.find('.cp-fileupload-table-cancel').addClass('success').html('').append(h('span.fa.fa-check')); var $pv = $row.find('.cp-fileupload-table-progress-value'); - var $pb = $row.find('.cp-fileupload-table-progress-container'); - var $pc = $row.find('.cp-fileupload-table-progress'); + var $pb = $row.find('.cp-fileupload-table-progressbar'); var $link = $row.find('.cp-fileupload-table-link'); /** @@ -190,7 +192,7 @@ define([ else { File.$container.fadeOut(); } - }, 20000); + }, 60000); return; } if (queue.inProgress) { return; } @@ -209,8 +211,9 @@ define([ window.setTimeout(function () { $table.show(); }); var estimate = obj.dl ? obj.size : FileCrypto.computeEncryptedSize(obj.blob.byteLength, obj.metadata); - var $progressBar = $('
    ', {'class':'cp-fileupload-table-progress-container'}); - var $progressValue = $('', {'class':'cp-fileupload-table-progress-value'}).text(Messages.upload_pending); + var $progressContainer = $('
    ', {'class':'cp-fileupload-table-progress-container'}); + $('
    ', {'class':'cp-fileupload-table-progressbar'}).appendTo($progressContainer); + $('', {'class':'cp-fileupload-table-progress-value'}).text(Messages.upload_pending).appendTo($progressContainer); var $tr = $('
    ').text(obj.dl ? Messages.download_dl : Messages.upload_up).appendTo($tr); + var typeIcon; + if (obj.dl) { typeIcon = h('span.fa.fa-arrow-down', { title: Messages.download_dl }); } + else { typeIcon = h('span.fa.fa-arrow-up', { title: Messages.upload_up }); } + + // type (download / upload) + $('', {'class': 'cp-fileupload-table-type'}).append(typeIcon).appendTo($tr); + // name $('').append($link).appendTo($tr); + // size $('').text(prettySize(estimate)).appendTo($tr); - $('', {'class': 'cp-fileupload-table-progress'}).append($progressBar).append($progressValue).appendTo($tr); + // progress + $('', {'class': 'cp-fileupload-table-progress'}).append($progressContainer).appendTo($tr); + // cancel $('', {'class': 'cp-fileupload-table-cancel'}).append($cancel).appendTo($tr); queue.next(); @@ -264,10 +276,9 @@ define([ input: initialDisabled }); return manualStore; - } + }; var fileUploadModal = function (defaultFileName, cb) { var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(defaultFileName) || []; - var name = parsedName[1] || defaultFileName; var ext = parsedName[2] || ""; var manualStore = createManualStore(); @@ -325,7 +336,7 @@ define([ }); }; - var showFolderUploadModal = File.showFolderUploadModal = function (foldername, cb) { + File.showFolderUploadModal = function (foldername, cb) { var manualStore = createManualStore(); // Ask for name, password and owner @@ -374,7 +385,7 @@ define([ forceSave: forceSave }); }); - } + }; var handleFileState = { queue: [], @@ -537,12 +548,16 @@ define([ var $row = $table.find('tr[id="'+id+'"]'); var $pv = $row.find('.cp-fileupload-table-progress-value'); - var $pb = $row.find('.cp-fileupload-table-progress-container'); - var $pc = $row.find('.cp-fileupload-table-progress'); + var $pb = $row.find('.cp-fileupload-table-progressbar'); var $link = $row.find('.cp-fileupload-table-link'); var done = function () { - $row.find('.cp-fileupload-table-cancel').text('-'); + $row.find('.cp-fileupload-table-cancel').addClass('success').html('').append(h('span.fa.fa-check')); + queue.inProgress = false; + queue.next(); + }; + var cancelled = function () { + $row.find('.cp-fileupload-table-cancel').addClass('cancelled').html('').append(h('span.fa.fa-minus')); queue.inProgress = false; queue.next(); }; @@ -594,9 +609,11 @@ define([ dl.cancel(); $cancel.remove(); $row.find('.cp-fileupload-table-progress-value').text(Messages.upload_cancelled); - done(); + cancelled(); }); - $row.find('.cp-fileupload-table-cancel').html('').append($cancel); + $row.find('.cp-fileupload-table-cancel') + .html('') + .append($cancel); }; queue.push({ dl: todo, From e949c2a6f75a4074b8b96dbc7778a8f4ab471453 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Tue, 30 Jul 2019 13:30:52 +0200 Subject: [PATCH 19/38] Add dummy convert folder to shared folder --- www/common/proxy-manager.js | 8 ++++++++ www/common/userObject.js | 14 ++++++++++++++ www/drive/inner.js | 36 +++++++++++++++++++++++++++++------- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index 1257f3ad4..d35df4e68 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -1071,6 +1071,13 @@ define([ } return Env.user.userObject.hasSubfolder(el, trashRoot); }; + var hasSubSharedFolder = function (Env, el, trashRoot) { + if (Env.folders[el]) { + var uo = Env.folders[el].userObject; + return uo.hasSubSharedFolder(uo.find[uo.ROOT]); + } + return Env.user.userObject.hasSubSharedFolder(el, trashRoot); + }; var hasFile = function (Env, el, trashRoot) { if (Env.folders[el]) { var uo = Env.folders[el].userObject; @@ -1140,6 +1147,7 @@ define([ isInTrashRoot: callWithEnv(isInTrashRoot), comparePath: callWithEnv(comparePath), hasSubfolder: callWithEnv(hasSubfolder), + hasSubSharedFolder: callWithEnv(hasSubSharedFolder), hasFile: callWithEnv(hasFile), // Data user: Env.user, diff --git a/www/common/userObject.js b/www/common/userObject.js index 39b55484a..be770232b 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -156,6 +156,20 @@ define([ } }; + exp.hasSubSharedFolder = function (folder) { + for (var el in folder) { + if (isSharedFolder(folder[el])) { + return true; + } + else if (isFolder(folder[el])) { + if (exp.hasSubSharedFolder(folder[el])) { + return true; + } + } + } + return false; + } + // Get data from AllFiles (Cryptpad_RECENTPADS) var getFileData = exp.getFileData = function (file) { if (!file) { return; } diff --git a/www/drive/inner.js b/www/drive/inner.js index fd7723bca..1694564f9 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -996,6 +996,7 @@ define([ // Can't rename or delete root elements hide.push('delete'); hide.push('rename'); + hide.push('share'); hide.push('color'); } if (!$element.is('.cp-app-drive-element-owned')) { @@ -1022,8 +1023,9 @@ define([ } } else if ($element.is('.cp-app-drive-element-sharedf')) { if (containsFolder) { - // More than 1 folder selected: cannot create a new subfolder + // More than 1 shared folder selected: cannot create a new subfolder hide.push('newfolder'); + hide.push('share'); hide.push('expandall'); hide.push('collapseall'); } @@ -1036,13 +1038,13 @@ define([ if (containsFolder) { // More than 1 folder selected: cannot create a new subfolder hide.push('newfolder'); + hide.push('share'); hide.push('expandall'); hide.push('collapseall'); } 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 @@ -3568,7 +3570,7 @@ define([ var parsed, modal; var friends = common.getFriends(); - if (manager.isSharedFolder(el)) { + if (manager.isSharedFolder(el)) { // Shared Folder data = manager.getSharedFolderData(el); parsed = Hash.parsePadUrl(data.href); modal = UIElements.createSFShareModal({ @@ -3582,7 +3584,27 @@ define([ editHash: parsed.hash } }); - } else { + UI.openCustomModal(modal, { + wide: Object.keys(friends).length !== 0 + }); + } else if (manager.isFolder(el)) { // Folder + // if folder already contains SF + if (manager.isInSharedFolder(paths[0].path)) { + UI.alert(Messages.convertFolderToSF_SFParent || "Sharing this folder can't be done because it already in a Shared Folder. Please, move this folder elsewhere in order to continue", undefined, true); + } + // if folder is inside SF + else if (manager.hasSubSharedFolder(el)) { + UI.alert(Messages.convertFolderToSF_SFChildren || "Sharing this folder can't be done because it already contains one ore more Shared Folders. Please, remove those from this folder in order to continue.", undefined, true); + } + // if folder does not contains SF + else { + UI.confirm(Messages.convertFolderToSF_confirm || "In order to be shared, this folder must be converted into a shared folder. Proceed ?", function(res) { + if (!res) { return; } + if (paths[0].path.length <= 1) { return; } // if root + // convert folder to Shared Folder + }); + } + } else { // File data = manager.getFileData(el); parsed = Hash.parsePadUrl(data.href); var roParsed = Hash.parsePadUrl(data.roHref); @@ -3608,10 +3630,10 @@ define([ modal = padType === 'file' ? UIElements.createFileShareModal(padData) : UIElements.createShareModal(padData); modal = UI.dialog.tabs(modal); + UI.openCustomModal(modal, { + wide: Object.keys(friends).length !== 0 + }); } - UI.openCustomModal(modal, { - wide: Object.keys(friends).length !== 0 - }); } else if ($(this).hasClass('cp-app-drive-context-newfolder')) { if (paths.length !== 1) { return; } From 4a93d1829a9dc5f08418753dab52b02168c37ecc Mon Sep 17 00:00:00 2001 From: ClemDee Date: Tue, 30 Jul 2019 16:37:35 +0200 Subject: [PATCH 20/38] Fix isFolderEmpty function in userObject --- www/common/userObject.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/common/userObject.js b/www/common/userObject.js index be770232b..eed9fc19c 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -109,7 +109,9 @@ define([ }; exp.isFolderEmpty = function (element) { if (!isFolder(element)) { return false; } - return Object.keys(element).length === 0; + if (Object.keys(element).length === 0) { return true; } + if (Object.keys(element).length === 1 && isFolderData(element[Object.keys(element)[0]])) { return true; } + return false; }; exp.hasSubfolder = function (element, trashRoot) { From 1cddd99baa9d098c27c0d71ec918ea2744617563 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Tue, 30 Jul 2019 16:39:28 +0200 Subject: [PATCH 21/38] Convert folder into shared folders now working --- www/common/proxy-manager.js | 67 +++++++++++++++++++++++++++++++++++++ www/common/userObject.js | 4 +-- www/drive/inner.js | 2 +- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index d35df4e68..7b79bcb14 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -461,6 +461,62 @@ define([ cb(id); }); }; + + // convert a folder to a Shared Folder + var _convertFolderToSharedFolder = function (Env, data, cb) { + var path = data.path; + var folderElement = Env.user.userObject.find(path); + if (data.path.length <= 1) { return; } + if (_isInSharedFolder(Env, path)) { return; } + if (Env.user.userObject.hasSubSharedFolder(folderElement)) { return; } + var parentPath = path.slice(0, -1); + var parentFolder = Env.user.userObject.find(parentPath); + var folderName = path[path.length - 1]; + var SFId; + var sharedFolderElement; + nThen(function (waitFor) { + // create shared folder + _addSharedFolder(Env, { + path: parentPath, + name: folderName, + owned: true, + password: '', + }, waitFor(function (id) { SFId = id; })); + }).nThen(function (waitFor) { + // move everything from folder to SF + if (!SFId) { return void cb(); } + var paths = []; + for (var el in folderElement) { + if (Env.user.userObject.isFolder(folderElement[el]) || Env.user.userObject.isFile(folderElement[el])) { + paths.push(path.concat(el)); + } + } + var SFKey = Object.keys(parentFolder).find(function (el) { + return parentFolder[el] === SFId; + }); + var newPath = parentPath.concat(SFKey).concat(UserObject.ROOT); + sharedFolderElement = Env.user.proxy[UserObject.SHARED_FOLDERS][SFId]; + _move(Env, { + paths: paths, + newPath: newPath, + copy: false, + }, waitFor()); + }).nThen(function (waitFor) { + // migrate metadata + var metadata = Env.user.userObject.getFolderData(folderElement); + for (var key in metadata) { + if (key === "metadata") { continue; } + sharedFolderElement[key] = metadata[key]; + } + }).nThen(function (waitFor) { + // remove folder + Env.user.userObject.delete([path], waitFor()); + }).nThen(function () { + // call callback + cb(); + }); + } + // Delete permanently some pads or folders var _delete = function (Env, data, cb) { data = data || {}; @@ -598,6 +654,8 @@ define([ _addFolder(Env, data, cb); break; case 'addSharedFolder': _addSharedFolder(Env, data, cb); break; + case 'convertFolderToSharedFolder': + _convertFolderToSharedFolder(Env, data, cb); break; case 'delete': _delete(Env, data, cb); break; case 'emptyTrash': @@ -914,6 +972,14 @@ define([ } }, cb); }; + var convertFolderToSharedFolderInner = function (Env, path, cb) { + return void Env.sframeChan.query("Q_DRIVE_USEROBJECT", { + cmd: "convertFolderToSharedFolder", + data: { + path: path + } + }, cb); + }; var deleteInner = function (Env, paths, cb) { return void Env.sframeChan.query("Q_DRIVE_USEROBJECT", { cmd: "delete", @@ -1117,6 +1183,7 @@ define([ emptyTrash: callWithEnv(emptyTrashInner), addFolder: callWithEnv(addFolderInner), addSharedFolder: callWithEnv(addSharedFolderInner), + convertFolderToSharedFolder: callWithEnv(convertFolderToSharedFolderInner), delete: callWithEnv(deleteInner), restore: callWithEnv(restoreInner), setFolderData: callWithEnv(setFolderDataInner), diff --git a/www/common/userObject.js b/www/common/userObject.js index eed9fc19c..9bf3487d6 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -158,13 +158,13 @@ define([ } }; - exp.hasSubSharedFolder = function (folder) { + var hasSubSharedFolder = exp.hasSubSharedFolder = function (folder) { for (var el in folder) { if (isSharedFolder(folder[el])) { return true; } else if (isFolder(folder[el])) { - if (exp.hasSubSharedFolder(folder[el])) { + if (hasSubSharedFolder(folder[el])) { return true; } } diff --git a/www/drive/inner.js b/www/drive/inner.js index 1694564f9..456e91efb 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3601,7 +3601,7 @@ define([ UI.confirm(Messages.convertFolderToSF_confirm || "In order to be shared, this folder must be converted into a shared folder. Proceed ?", function(res) { if (!res) { return; } if (paths[0].path.length <= 1) { return; } // if root - // convert folder to Shared Folder + manager.convertFolderToSharedFolder(paths[0].path, refresh); }); } } else { // File From 27502c61b15af9479440782b90af1b5c261b34d0 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Tue, 30 Jul 2019 17:25:38 +0200 Subject: [PATCH 22/38] Fix lint issues --- www/common/proxy-manager.js | 4 ++-- www/common/userObject.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index 7b79bcb14..f75fd0aa7 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -501,7 +501,7 @@ define([ newPath: newPath, copy: false, }, waitFor()); - }).nThen(function (waitFor) { + }).nThen(function () { // migrate metadata var metadata = Env.user.userObject.getFolderData(folderElement); for (var key in metadata) { @@ -515,7 +515,7 @@ define([ // call callback cb(); }); - } + }; // Delete permanently some pads or folders var _delete = function (Env, data, cb) { diff --git a/www/common/userObject.js b/www/common/userObject.js index 9bf3487d6..109928e81 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -170,7 +170,7 @@ define([ } } return false; - } + }; // Get data from AllFiles (Cryptpad_RECENTPADS) var getFileData = exp.getFileData = function (file) { From 21658e9de1d2ffa9abb41c033dd2280afe02b0bb Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 12 Aug 2019 15:52:48 +0200 Subject: [PATCH 23/38] Fix restoring an older version of the drive --- www/common/cryptpad-common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index fef46951c..e761f0ad5 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -138,7 +138,7 @@ define([ } postMessage("SET", { key:['drive'], - value: data + value: data.drive }, function (obj) { cb(obj); }, { From bbd59c6a2b7a0bf002bc023b335b1e9c9f38f7d2 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 12 Aug 2019 16:14:44 +0200 Subject: [PATCH 24/38] Don't freeze the UI with old (invalid) states of the drive history --- www/common/proxy-manager.js | 4 ++++ www/common/userObject.js | 14 ++++++++++++++ www/drive/inner.js | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index 1257f3ad4..7f20ae5b6 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -1036,6 +1036,9 @@ define([ var isInSharedFolder = _isInSharedFolder; /* Generic: doesn't need access to a proxy */ + var isValidDrive = function (Env, obj) { + return Env.user.userObject.isValidDrive(obj); + }; var isFile = function (Env, el, allowStr) { return Env.user.userObject.isFile(el, allowStr); }; @@ -1131,6 +1134,7 @@ define([ getUserObjectPath: callWithEnv(getUserObjectPath), isDuplicateOwned: callWithEnv(isDuplicateOwned), // Generic + isValidDrive: callWithEnv(isValidDrive), isFile: callWithEnv(isFile), isFolder: callWithEnv(isFolder), isSharedFolder: callWithEnv(isSharedFolder), diff --git a/www/common/userObject.js b/www/common/userObject.js index 39b55484a..fe99f9935 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -72,8 +72,22 @@ define([ a[TRASH] = {}; a[FILES_DATA] = {}; a[TEMPLATE] = []; + a[SHARED_FOLDERS] = {}; return a; }; + + var type = function (dat) { + return dat === null? 'null': Array.isArray(dat)?'array': typeof(dat); + }; + exp.isValidDrive = function (obj) { + var base = exp.getStructure(); + return typeof (obj) === "object" && + Object.keys(base).every(function (key) { + console.log(key, obj[key], type(obj[key])); + return obj[key] && type(base[key]) === type(obj[key]); + }); + }; + var getHrefArray = function () { return [TEMPLATE]; }; diff --git a/www/drive/inner.js b/www/drive/inner.js index f69c36060..606de2866 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3900,6 +3900,10 @@ define([ return; } history.sfId = false; + + var ok = manager.isValidDrive(obj.drive); + if (!ok) { return; } + copyObjectValue(files, obj.drive); appStatus.isReady = true; refresh(); From 23dc301eb19dc27ed249edd4a21da91dde56fef8 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Mon, 12 Aug 2019 18:44:25 +0200 Subject: [PATCH 25/38] Small fixes in sframe-common-file --- www/common/sframe-common-file.js | 16 ++++++++-------- www/drive/inner.js | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 8f71d281b..b07bc8854 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -103,7 +103,7 @@ define([ var $row = $table.find('tr[id="'+id+'"]'); - $row.find('.cp-fileupload-table-cancel').addClass('success').html('').append(h('span.fa.fa-check')); + $row.find('.cp-fileupload-table-cancel').addClass('success').html('').append(h('span.fa.fa-minus')); var $pv = $row.find('.cp-fileupload-table-progress-value'); var $pb = $row.find('.cp-fileupload-table-progressbar'); var $link = $row.find('.cp-fileupload-table-link'); @@ -301,7 +301,7 @@ define([ ]); $(content).find('#cp-upload-owned').on('change', function () { - var val = $(content).find('#cp-upload-owned').is(':checked'); + var val = Util.isCheked($(content).find('#cp-upload-owned')); if (val) { $(content).find('#cp-upload-store').prop('checked', true).prop('disabled', true); } else { @@ -315,8 +315,8 @@ define([ // Get the values var newName = $(content).find('#cp-upload-name').val(); var password = $(content).find('#cp-upload-password').val() || undefined; - var owned = $(content).find('#cp-upload-owned').is(':checked'); - var forceSave = owned || $(content).find('#cp-upload-store').is(':checked'); + var owned = Util.isChecked($(content).find('#cp-upload-owned')); + var forceSave = owned || Util.isChecked($(content).find('#cp-upload-store')); modalState.owned = owned; modalState.store = forceSave; @@ -356,7 +356,7 @@ define([ ]); $(content).find('#cp-upload-owned').on('change', function () { - var val = $(content).find('#cp-upload-owned').is(':checked'); + var val = Util.isChecked($(content).find('#cp-upload-owned')); if (val) { $(content).find('#cp-upload-store').prop('checked', true).prop('disabled', true); } else { @@ -370,8 +370,8 @@ define([ // Get the values var newName = $(content).find('#cp-upload-foldername').val(); var password = $(content).find('#cp-upload-password').val() || undefined; - var owned = $(content).find('#cp-upload-owned').is(':checked'); - var forceSave = owned || $(content).find('#cp-upload-store').is(':checked'); + var owned = Util.isChecked($(content).find('#cp-upload-owned')); + var forceSave = owned || Util.isChecked($(content).find('#cp-upload-store')); modalState.owned = owned; modalState.store = forceSave; @@ -436,7 +436,7 @@ define([ password = defaultOptions.password || undefined; owned = !!defaultOptions.owned; forceSave = !!defaultOptions.forceSave; - finish(); + return void finish(); } // if no default options were passed, ask the user else { diff --git a/www/drive/inner.js b/www/drive/inner.js index bf01942f4..155ed7ac0 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -2210,7 +2210,6 @@ define([ }); }; var showUploadFolderModal = function () { - console.log("%cIMPORT FOLDER", "color: red"); var $input = $('', { 'type': 'file', 'style': 'display: none;', From 2a2f45ec2553e3515174f4517a0d99b428b3cc14 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 14 Aug 2019 10:36:53 +0200 Subject: [PATCH 26/38] Remove translation fallbacks --- www/common/sframe-common-file.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index b07bc8854..489a8b0ec 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -272,7 +272,7 @@ define([ var initialState = modalState.owned || modalState.store; var initialDisabled = modalState.owned ? { disabled: true } : {}; var manualStore = autoStore === 1 ? undefined : - UI.createCheckbox('cp-upload-store', isFolderUpload ? (Messages.uploadFolder_modal_forceSave || "Store files in your cryptDrive") : Messages.autostore_forceSave, initialState, { + UI.createCheckbox('cp-upload-store', isFolderUpload ? (Messages.uploadFolder_modal_forceSave) : Messages.autostore_forceSave, initialState, { input: initialDisabled }); return manualStore; @@ -341,15 +341,14 @@ define([ // Ask for name, password and owner var content = h('div', [ - h('h4', Messages.uploadFolder_modal_title || "Folder upload options"), + h('h4', Messages.uploadFolder_modal_title), UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages.fm_folderName), h('input#cp-upload-foldername', {type: 'text', placeholder: foldername, value: foldername}), - h('label', {for: 'cp-upload-password'}, Messages.uploadFolder_modal_filesPassword || "Files password"), + h('label', {for: 'cp-upload-password'}, Messages.uploadFolder_modal_filesPassword), UI.passwordInput({id: 'cp-upload-password'}), h('span', { style: 'display:flex;align-items:center;justify-content:space-between' }, [ - UI.createCheckbox('cp-upload-owned', Messages.uploadFolder_modal_owner || "Owned files", modalState.owned), createHelper('/faq.html#keywords-owned', Messages.creation_owned1) ]), manualStore From f2063f37484bedcd0fcc28dc389b93497d3d61be Mon Sep 17 00:00:00 2001 From: ClemDee Date: Fri, 16 Aug 2019 13:56:25 +0200 Subject: [PATCH 27/38] Remove translation fallbacks --- www/drive/inner.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/www/drive/inner.js b/www/drive/inner.js index 456e91efb..7898e62d1 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3590,15 +3590,15 @@ define([ } else if (manager.isFolder(el)) { // Folder // if folder already contains SF if (manager.isInSharedFolder(paths[0].path)) { - UI.alert(Messages.convertFolderToSF_SFParent || "Sharing this folder can't be done because it already in a Shared Folder. Please, move this folder elsewhere in order to continue", undefined, true); + UI.alert(Messages.convertFolderToSF_SFParent, undefined, true); } // if folder is inside SF else if (manager.hasSubSharedFolder(el)) { - UI.alert(Messages.convertFolderToSF_SFChildren || "Sharing this folder can't be done because it already contains one ore more Shared Folders. Please, remove those from this folder in order to continue.", undefined, true); + UI.alert(Messages.convertFolderToSF_SFChildren, undefined, true); } // if folder does not contains SF else { - UI.confirm(Messages.convertFolderToSF_confirm || "In order to be shared, this folder must be converted into a shared folder. Proceed ?", function(res) { + UI.confirm(Messages.convertFolderToSF_confirm, function(res) { if (!res) { return; } if (paths[0].path.length <= 1) { return; } // if root manager.convertFolderToSharedFolder(paths[0].path, refresh); From 58a3f76464c890671ae175e57b36bac30d3eb919 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Fri, 16 Aug 2019 14:35:07 +0200 Subject: [PATCH 28/38] Fix two comments --- www/drive/inner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/drive/inner.js b/www/drive/inner.js index 7898e62d1..71dd1e4d3 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3588,11 +3588,11 @@ define([ wide: Object.keys(friends).length !== 0 }); } else if (manager.isFolder(el)) { // Folder - // if folder already contains SF + // if folder is inside SF if (manager.isInSharedFolder(paths[0].path)) { UI.alert(Messages.convertFolderToSF_SFParent, undefined, true); } - // if folder is inside SF + // if folder already contains SF else if (manager.hasSubSharedFolder(el)) { UI.alert(Messages.convertFolderToSF_SFChildren, undefined, true); } From 1af467aa8493e6945ce56ce82180ccf72b67079b Mon Sep 17 00:00:00 2001 From: Weblate Date: Fri, 16 Aug 2019 14:51:04 +0000 Subject: [PATCH 29/38] Translated using Weblate (French) Currently translated at 100.0% (1039 of 1039 strings) Translation: CryptPad/App Translate-URL: http://weblate.cryptpad.fr/projects/cryptpad/app/fr/ --- www/common/translations/messages.fr.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/www/common/translations/messages.fr.json b/www/common/translations/messages.fr.json index 958acaeee..5474ba921 100644 --- a/www/common/translations/messages.fr.json +++ b/www/common/translations/messages.fr.json @@ -1124,5 +1124,14 @@ "requestEdit_accepted": "{1} vous a accordé les droits d'édition du pad {0}", "requestEdit_sent": "Demande envoyée", "uploadFolderButton": "Importer un dossier", - "properties_unknownUser": "{0} utilisateur(s) inconnu(s)" + "properties_unknownUser": "{0} utilisateur(s) inconnu(s)", + "fm_morePads": "Plus de pads", + "fc_openInCode": "Ouvrir dans l'application Code", + "uploadFolder_modal_title": "Options d'importation du dossier", + "uploadFolder_modal_filesPassword": "Mot de passe des fichiers", + "uploadFolder_modal_owner": "Être propriétaire des fichiers", + "uploadFolder_modal_forceSave": "Stocker les fichiers dans votre CryptDrive", + "convertFolderToSF_SFParent": "Impossible de convertir ce dossier en dossier partagé car il se situe à l'interieur d'un autre dossier partagé. Veuillez le déplacer à l'extérieur afin de continuer.", + "convertFolderToSF_SFChildren": "Impossible de convertir ce dossier en dossier partagé car il contient déjà d'autres dossiers partagés. Veuillez déplacer ces dossiers à l'extérieur afin de continuer.", + "convertFolderToSF_confirm": "Ce dossier va être converti en dossier partagé afin de pouvoir être accessible par d'autres utilisateurs. Continuer ?" } From 7d583975b886d171af462ddb01aba4a4ce9f0356 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 19 Aug 2019 11:56:52 +0200 Subject: [PATCH 30/38] fix a few things, add comments for others --- www/common/proxy-manager.js | 68 +++++++++++++++++++++++++------------ www/common/userObject.js | 2 ++ www/drive/inner.js | 16 ++++----- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index f75fd0aa7..0e4baa799 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -466,36 +466,61 @@ define([ var _convertFolderToSharedFolder = function (Env, data, cb) { var path = data.path; var folderElement = Env.user.userObject.find(path); - if (data.path.length <= 1) { return; } - if (_isInSharedFolder(Env, path)) { return; } - if (Env.user.userObject.hasSubSharedFolder(folderElement)) { return; } + // don't try to convert top-level elements (trash, root, etc) to shared-folders + // TODO also validate that you're in root (not templates, etc) + if (data.path.length <= 1) { + // XXX call back with error and abort nThen + return; + } + if (_isInSharedFolder(Env, path)) { + // XXX call back with error and abort nThen + return; + } + if (Env.user.userObject.hasSubSharedFolder(folderElement)) { + // XXX call back with error and abort nThen + return; + } var parentPath = path.slice(0, -1); var parentFolder = Env.user.userObject.find(parentPath); var folderName = path[path.length - 1]; var SFId; - var sharedFolderElement; nThen(function (waitFor) { // create shared folder _addSharedFolder(Env, { path: parentPath, name: folderName, - owned: true, - password: '', - }, waitFor(function (id) { SFId = id; })); + owned: true, // FIXME hardcoded preference + password: '', // FIXME hardcoded preference + }, waitFor(function (id) { + // _addSharedFolder can be an id or an error + if (typeof(id) === 'object' && id && id.error) { + // XXX FIXME handle error + } else { + SFId = id; + } + })); }).nThen(function (waitFor) { // move everything from folder to SF - if (!SFId) { return void cb(); } + if (!SFId) { + // XXX FIXME callback does not indicate that there is an error + // XXX FIXME does not abort nThen chain + return void cb(); + } var paths = []; for (var el in folderElement) { if (Env.user.userObject.isFolder(folderElement[el]) || Env.user.userObject.isFile(folderElement[el])) { paths.push(path.concat(el)); } } - var SFKey = Object.keys(parentFolder).find(function (el) { - return parentFolder[el] === SFId; + var SFKey; + // this is basically Array.find, except it works in IE + Object.keys(parentFolder).some(function (el) { + if (parentFolder[el] === SFId) { + SFKey = el; + return true; + } }); var newPath = parentPath.concat(SFKey).concat(UserObject.ROOT); - sharedFolderElement = Env.user.proxy[UserObject.SHARED_FOLDERS][SFId]; _move(Env, { paths: paths, newPath: newPath, @@ -503,17 +528,20 @@ define([ }, waitFor()); }).nThen(function () { // migrate metadata + var sharedFolderElement = Env.user.proxy[UserObject.SHARED_FOLDERS][SFId]; var metadata = Env.user.userObject.getFolderData(folderElement); for (var key in metadata) { + // it shouldn't be possible to have nested metadata + // but this is a reasonable sanity check if (key === "metadata") { continue; } + // copy the metadata from the original folder to the new shared folder sharedFolderElement[key] = metadata[key]; } - }).nThen(function (waitFor) { + // remove folder - Env.user.userObject.delete([path], waitFor()); - }).nThen(function () { - // call callback - cb(); + Env.user.userObject.delete([path], function () { + cb(); + }); }); }; @@ -1137,12 +1165,8 @@ define([ } return Env.user.userObject.hasSubfolder(el, trashRoot); }; - var hasSubSharedFolder = function (Env, el, trashRoot) { - if (Env.folders[el]) { - var uo = Env.folders[el].userObject; - return uo.hasSubSharedFolder(uo.find[uo.ROOT]); - } - return Env.user.userObject.hasSubSharedFolder(el, trashRoot); + var hasSubSharedFolder = function (Env, el) { + return Env.user.userObject.hasSubSharedFolder(el); }; var hasFile = function (Env, el, trashRoot) { if (Env.folders[el]) { diff --git a/www/common/userObject.js b/www/common/userObject.js index 109928e81..cea2a72c0 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -109,7 +109,9 @@ define([ }; exp.isFolderEmpty = function (element) { if (!isFolder(element)) { return false; } + // if the folder contains nothing, it's empty if (Object.keys(element).length === 0) { return true; } + // or if it contains one thing and that thing is metadata if (Object.keys(element).length === 1 && isFolderData(element[Object.keys(element)[0]])) { return true; } return false; }; diff --git a/www/drive/inner.js b/www/drive/inner.js index 71dd1e4d3..5b96643a9 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -993,7 +993,7 @@ define([ hide.push('collapseall'); } if (path.length === 1) { - // Can't rename or delete root elements + // Can't rename, share, delete, or change the color of root elements hide.push('delete'); hide.push('rename'); hide.push('share'); @@ -1023,9 +1023,8 @@ define([ } } else if ($element.is('.cp-app-drive-element-sharedf')) { if (containsFolder) { - // More than 1 shared folder selected: cannot create a new subfolder + // More than 1 folder selected: cannot create a new subfolder hide.push('newfolder'); - hide.push('share'); hide.push('expandall'); hide.push('collapseall'); } @@ -1038,7 +1037,6 @@ define([ if (containsFolder) { // More than 1 folder selected: cannot create a new subfolder hide.push('newfolder'); - hide.push('share'); hide.push('expandall'); hide.push('collapseall'); } @@ -3570,7 +3568,7 @@ define([ var parsed, modal; var friends = common.getFriends(); - if (manager.isSharedFolder(el)) { // Shared Folder + if (manager.isSharedFolder(el)) { data = manager.getSharedFolderData(el); parsed = Hash.parsePadUrl(data.href); modal = UIElements.createSFShareModal({ @@ -3584,21 +3582,21 @@ define([ editHash: parsed.hash } }); - UI.openCustomModal(modal, { + return void UI.openCustomModal(modal, { wide: Object.keys(friends).length !== 0 }); } else if (manager.isFolder(el)) { // Folder // if folder is inside SF if (manager.isInSharedFolder(paths[0].path)) { - UI.alert(Messages.convertFolderToSF_SFParent, undefined, true); + return void UI.alert(Messages.convertFolderToSF_SFParent); } // if folder already contains SF else if (manager.hasSubSharedFolder(el)) { - UI.alert(Messages.convertFolderToSF_SFChildren, undefined, true); + return void UI.alert(Messages.convertFolderToSF_SFChildren); } // if folder does not contains SF else { - UI.confirm(Messages.convertFolderToSF_confirm, function(res) { + return void UI.confirm(Messages.convertFolderToSF_confirm, function(res) { if (!res) { return; } if (paths[0].path.length <= 1) { return; } // if root manager.convertFolderToSharedFolder(paths[0].path, refresh); From a368948fb64407f939976dc80a8c1eda1b7220c2 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 19 Aug 2019 12:06:06 +0200 Subject: [PATCH 31/38] handle errors when converting folders to shared folders --- www/common/proxy-manager.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index 0e4baa799..c372d4aea 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -469,16 +469,19 @@ define([ // don't try to convert top-level elements (trash, root, etc) to shared-folders // TODO also validate that you're in root (not templates, etc) if (data.path.length <= 1) { - // XXX call back with error and abort nThen - return; + return void cb({ + error: 'E_INVAL_PATH', + }); } if (_isInSharedFolder(Env, path)) { - // XXX call back with error and abort nThen - return; + return void cb({ + error: 'E_INVAL_NESTING', + }); } if (Env.user.userObject.hasSubSharedFolder(folderElement)) { - // XXX call back with error and abort nThen - return; + return void cb({ + error: 'E_INVAL_NESTING', + }); } var parentPath = path.slice(0, -1); var parentFolder = Env.user.userObject.find(parentPath); @@ -489,12 +492,13 @@ define([ _addSharedFolder(Env, { path: parentPath, name: folderName, - owned: true, // FIXME hardcoded preference - password: '', // FIXME hardcoded preference + owned: true, // XXX FIXME hardcoded preference + password: '', // XXX FIXME hardcoded preference }, waitFor(function (id) { // _addSharedFolder can be an id or an error if (typeof(id) === 'object' && id && id.error) { - // XXX FIXME handle error + waitFor.abort(); + return void cb(id); } else { SFId = id; } @@ -502,9 +506,10 @@ define([ }).nThen(function (waitFor) { // move everything from folder to SF if (!SFId) { - // XXX FIXME callback does not indicate that there is an error - // XXX FIXME does not abort nThen chain - return void cb(); + waitFor.abort(); + return void cb({ + error: 'E_NO_ID' + }); } var paths = []; for (var el in folderElement) { @@ -520,6 +525,13 @@ define([ return true; } }); + + if (!SFKey) { + waitFor.abort(); + return void cb({ + error: 'E_NO_KEY' + }); + } var newPath = parentPath.concat(SFKey).concat(UserObject.ROOT); _move(Env, { paths: paths, From 7988a3033857ece15daa1135617a825c73c096cd Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 19 Aug 2019 13:39:35 +0200 Subject: [PATCH 32/38] Fix folder upload UI --- www/common/sframe-common-file.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 4266289d8..3956c60a6 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -337,7 +337,7 @@ define([ }; File.showFolderUploadModal = function (foldername, cb) { - var manualStore = createManualStore(); + var manualStore = createManualStore(true); // Ask for name, password and owner var content = h('div', [ @@ -349,6 +349,7 @@ define([ h('span', { style: 'display:flex;align-items:center;justify-content:space-between' }, [ + UI.createCheckbox('cp-upload-owned', Messages.uploadFolder_modal_owner, modalState.owned), createHelper('/faq.html#keywords-owned', Messages.creation_owned1) ]), manualStore From 6f0062d0230cebe4e08bc4e5bafaa8fe22b0228f Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 19 Aug 2019 14:37:55 +0200 Subject: [PATCH 33/38] Add comments and timeout errors --- www/common/outer/async-store.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 417fd0fa8..e4a85a89c 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1241,6 +1241,10 @@ define([ channel.sendMessage(msg, clientId, cb); }; + // requestPadAccess is used to check if we have a way to contact the owner + // of the pad AND to send the request if we want + // data.send === false ==> check if we can contact them + // data.send === true ==> send the request Store.requestPadAccess = function (clientId, data, cb) { var owner = data.owner; var channel = channels[data.channel]; @@ -1255,13 +1259,15 @@ define([ } if (i >= 300) { // One minute timeout clearInterval(it); + return void cb({error: 'ETIMEOUT'}); } i++; }, 200); return; } - // If the owner was not is the pad metadata, check if it is a friend + // If the owner was not is the pad metadata, check if it is a friend. + // We'll contact the first owner for whom we know the mailbox var fData = channel.data || {}; if (!owner && fData.owners) { var friends = store.proxy.friends || {}; @@ -1348,6 +1354,7 @@ define([ } if (i >= 300) { // One minute timeout clearInterval(it); + return void cb({error: 'ETIMEOUT'}); } i++; }, 200); From aedc92362a6d64b3a2b5a1cb2e2778212713ed83 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 19 Aug 2019 15:25:42 +0200 Subject: [PATCH 34/38] update chainpad-listmap dependency version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index b362c0a5f..1f9a3a698 100644 --- a/bower.json +++ b/bower.json @@ -30,7 +30,7 @@ "secure-fabric.js": "secure-v1.7.9", "hyperjson": "~1.4.0", "chainpad-crypto": "^0.2.0", - "chainpad-listmap": "^0.5.0", + "chainpad-listmap": "^0.7.0", "chainpad": "^5.1.0", "file-saver": "1.3.1", "alertifyjs": "1.0.11", From 656b12954331ce0e2b954797e14032bd762e924f Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 16 Aug 2019 11:09:24 +0200 Subject: [PATCH 35/38] Ability to remove handlers from worker-channel and metadata-manager --- www/common/make-backup.js | 7 +++---- www/common/metadata-manager.js | 9 +++++++++ www/common/outer/worker-channel.js | 12 ++++++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/www/common/make-backup.js b/www/common/make-backup.js index d9fb62d96..cb6f5bf2b 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -92,12 +92,11 @@ define([ var opts = { password: pData.password }; - var done = false; - ctx.sframeChan.on("EV_CRYPTGET_PROGRESS", function (data) { - if (done || data.hash !== parsed.hash) { return; } + var handler = ctx.sframeChan.on("EV_CRYPTGET_PROGRESS", function (data) { + if (data.hash !== parsed.hash) { return; } updateProgress.progress(data.progress); if (data.progress === 1) { - done = true; + handler.stop(); updateProgress.progress2(1); } }); diff --git a/www/common/metadata-manager.js b/www/common/metadata-manager.js index 02d516ff7..717705d84 100644 --- a/www/common/metadata-manager.js +++ b/www/common/metadata-manager.js @@ -194,6 +194,15 @@ define(['json.sortify'], function (Sortify) { onChange: function (f) { changeHandlers.push(f); }, onChangeLazy: function (f) { lazyChangeHandlers.push(f); }, onRequestSync: function (f) { syncHandlers.push(f); }, + off: function (name, f) { + var h = []; + if (name === 'change') { h = changeHandlers; } + else if (name === 'lazy') { h = lazyChangeHandlers; } + else if (name === 'title') { h = titleChangeHandlers; } + else if (name === 'sync') { h = syncHandlers; } + var idx = h.indexOf(f); + if (idx !== -1) { h.splice(idx, 1); } + }, isConnected : function () { return members.indexOf(meta.user.netfluxId) !== -1; }, diff --git a/www/common/outer/worker-channel.js b/www/common/outer/worker-channel.js index 3649ab0ea..42b91b802 100644 --- a/www/common/outer/worker-channel.js +++ b/www/common/outer/worker-channel.js @@ -81,17 +81,25 @@ define([ // If the type is a query, your handler will be invoked with a reply function that takes // one argument (the content to reply with). chan.on = function (queryType, handler, quiet) { - (handlers[queryType] = handlers[queryType] || []).push(function (data, msg) { + var h = function (data, msg) { handler(data.content, function (replyContent) { postMsg(JSON.stringify({ txid: data.txid, content: replyContent })); }, msg); - }); + }; + (handlers[queryType] = handlers[queryType] || []).push(h); if (!quiet) { event('EV_REGISTER_HANDLER', queryType); } + return { + stop: function () { + var idx = handlers[queryType].indexOf(h); + if (idx === -1) { return; } + handlers[queryType].splice(idx, 1); + } + }; }; // If a particular handler is registered, call the callback immediately, otherwise it will be called From 92a41f84f7f199860fba72dbe18a682a02a6b184 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 19 Aug 2019 16:00:55 +0200 Subject: [PATCH 36/38] Fix wrong owner in the properties modal --- www/common/common-ui-elements.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index f3f2f5e6c..3b6c294bb 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -131,11 +131,14 @@ define([ data.owners.forEach(function (ed) { // If a friend is an owner, add their name to the list // otherwise, increment the list of strangers + if (ed === edPublic) { + names.push(Messages.yourself); + return; + } if (!Object.keys(priv.friends || {}).some(function (c) { var friend = priv.friends[c] || {}; - if (friend.edPublic !== ed) { return; } - var name = c === 'me' ? Messages.yourself : friend.displayName; - names.push(name); + if (friend.edPublic !== ed || c === 'me') { return; } + names.push(friend.displayName); return true; })) { strangers++; From 06809fd3ba0263a80da20c7b8a40a2f2d36cc969 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 19 Aug 2019 16:53:17 +0200 Subject: [PATCH 37/38] Update codemirror settings in realtime --- www/common/outer/async-store.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index b7ac2da26..2abcb1b1e 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -738,7 +738,10 @@ define([ var object = getAttributeObject(data.attr); object.obj[object.key] = data.value; } catch (e) { return void cb({error: e}); } - onSync(cb); + onSync(function () { + cb(); + broadcast([], "UPDATE_METADATA"); + }); }; Store.getAttribute = function (clientId, data, cb) { var object; From 15212205604013c4e1667df2d95f4925c6ef75d4 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 19 Aug 2019 17:32:37 +0200 Subject: [PATCH 38/38] fix loading screen spinner color to match CryptPad icon --- customize.dist/loading.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/customize.dist/loading.js b/customize.dist/loading.js index 765ec56f9..11a82f770 100644 --- a/customize.dist/loading.js +++ b/customize.dist/loading.js @@ -184,7 +184,7 @@ define([], function () { box-sizing: border-box; width: 80px; height: 80px; - border: 11px solid lightgrey; + border: 11px solid white; border-radius: 50%; border-top-color: transparent; animation: spin infinite 3s;