From 92ce3116940f90581686d221e7babb547617068e Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 17 Oct 2018 14:32:33 +0200 Subject: [PATCH] Basic CryptDrive export with pads --- bower.json | 3 +- www/common/sframe-common-outer.js | 9 +++ www/common/sframe-protocol.js | 6 +- www/common/translations/messages.js | 2 + www/settings/inner.js | 78 ++++++++++++++++++- www/settings/make-backup.js | 116 ++++++++++++++++++++++++++++ 6 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 www/settings/make-backup.js diff --git a/bower.json b/bower.json index 828045139..27b1ea1f4 100644 --- a/bower.json +++ b/bower.json @@ -46,7 +46,8 @@ "html2canvas": "^0.4.1", "croppie": "^2.5.0", "sortablejs": "#^1.6.0", - "saferphore": "^0.0.1" + "saferphore": "^0.0.1", + "jszip": "Stuk/jszip#^3.1.5" }, "resolutions": { "bootstrap": "^v4.0.0" diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 7960e596c..f40bd6514 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -744,6 +744,15 @@ define([ Cryptpad.removeLoginBlock(data, cb); }); + sframeChan.on('Q_CRYPTGET', function (data, cb) { + Cryptget.get(data.hash, function (err, val) { + cb({ + error: err, + data: val + }); + }, data.opts); + }); + if (cfg.addRpc) { cfg.addRpc(sframeChan, Cryptpad, Utils); } diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index 391cbf96a..f349ef8da 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -270,5 +270,9 @@ define({ 'Q_IS_PAD_STORED': true, // Import mediatag from a pad - 'Q_IMPORT_MEDIATAG': true + 'Q_IMPORT_MEDIATAG': true, + + // Ability to get a pad's content from its hash + 'Q_CRYPTGET': true, + }); diff --git a/www/common/translations/messages.js b/www/common/translations/messages.js index 5f10744d0..2c2addc8f 100644 --- a/www/common/translations/messages.js +++ b/www/common/translations/messages.js @@ -562,6 +562,8 @@ define(function () { out.settings_backupCategory = "Backup"; out.settings_backupHint = "Backup or restore all your CryptDrive's content. It won't contain the content of your pads, just the link to access them."; out.settings_backup = "Backup"; + out.settings_backupHint2 = "Download all your pads. Pads will be downloaded in an readable format when available."; + out.settings_backup2 = "Download my CryptDrive"; out.settings_restore = "Restore"; out.settings_resetNewTitle = "Clean CryptDrive"; diff --git a/www/settings/inner.js b/www/settings/inner.js index f05c8e335..f92b4348b 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -12,6 +12,7 @@ define([ '/customize/credential.js', '/customize/application_config.js', '/api/config', + '/settings/make-backup.js', '/bower_components/file-saver/FileSaver.min.js', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', @@ -30,7 +31,8 @@ define([ h, Cred, AppConfig, - ApiConfig + ApiConfig, + Backup, ) { var saveAs = window.saveAs; @@ -50,6 +52,7 @@ define([ 'cp-settings-autostore', 'cp-settings-userfeedback', 'cp-settings-change-password', + 'cp-settings-backup', 'cp-settings-delete' ], 'creation': [ @@ -300,6 +303,45 @@ define([ return $div; }; + create['backup'] = function () { + if (!common.isLoggedIn()) { return; } + var $div = $('
', { 'class': 'cp-settings-backup cp-sidebarlayout-element'}); + + $('', {'class': 'label'}).text(Messages.settings_backupTitle || 'TODO BACKUP').appendTo($div); // XXX + + $('', {'class': 'cp-sidebarlayout-description'}) + .append(Messages.settings_backupHint || 'TODO').appendTo($div); // XXX + + var $ok = $('', {'class': 'fa fa-check', title: Messages.saved}); + var $spinner = $('', {'class': 'fa fa-spinner fa-pulse'}); + + var $button = $('