From 7befaccd88ba38240620041600cd4c69563a3de3 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 18 May 2017 12:36:12 +0200 Subject: [PATCH] move more rpc calls into pinpad --- www/common/cryptpad-common.js | 15 +++++++++++++++ www/common/pinpad.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 2504efea8..14f0a8b66 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -779,6 +779,21 @@ define([ common.getPinnedUsage(todo); }; + common.uploadComplete = function (cb) { + if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); } + rpc.uploadComplete(cb); + }; + + common.uploadStatus = function (size, cb) { + if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); } + rpc.uploadStatus(size, cb); + }; + + common.uploadCancel = function (cb) { + if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); } + rpc.uploadCancel(cb); + }; + var LIMIT_REFRESH_RATE = 30000; // milliseconds common.createUsageBar = function (cb, alwaysDisplayUpgrade) { var todo = function (err, state, data) { diff --git a/www/common/pinpad.js b/www/common/pinpad.js index 5fe0b2b8e..c0b057cf8 100644 --- a/www/common/pinpad.js +++ b/www/common/pinpad.js @@ -144,6 +144,40 @@ define([ }); }; + exp.uploadComplete = function (cb) { + rpc.send('UPLOAD_COMPLETE', null, function (e, res) { + if (e) { return void cb(e); } + var id = res[0]; + if (typeof(id) !== 'string') { + return void cb('INVALID_ID'); + } + cb(void 0, id); + }); + }; + + exp.uploadStatus = function (size, cb) { + if (typeof(size) !== 'number') { + return void window.setTimeout(function () { + cb('INVALID_SIZE'); + }); + } + rpc.send('UPLOAD_STATUS', size, function (e, res) { + if (e) { return void cb(e); } + var pending = res[0]; + if (typeof(pending) !== 'boolean') { + return void cb('INVALID_RESPONSE'); + } + cb(void 0, pending); + }); + }; + + exp.uploadCancel = function (cb) { + rpc.send('UPLOAD_CANCEL', void 0, function (e, res) { + if (e) { return void cb(e); } + cb(); + }); + }; + cb(e, exp); }); };