From b762983cc31f24d9bd9e9e50f0829651af5e6577 Mon Sep 17 00:00:00 2001 From: Alexey Lunin <alexey.lunin@vereign.com> Date: Fri, 1 Mar 2019 05:35:07 +0400 Subject: [PATCH] Fix todo --- javascript/src/iframe/viamapi-iframe.js | 54 +++++++++++-------------- javascript/src/iframe/wopiapi-iframe.js | 3 -- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 811b242..bf62ba1 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -1080,42 +1080,34 @@ const connection = Penpal.connectToParent({ return collaboraApi.discovery().then(apps => apps); }, - // WOPI APIs - // TODO rewrite with async await - getPassports: function(fileID) { - return new Penpal.Promise(function(result) { - const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); + getPassports: async fileId => { + const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); - if ( - !authenticationPublicKey || - !window.loadedIdentities[authenticationPublicKey] || - !extendPinCodeTtl(authenticationPublicKey) - ) { - return encodeResponse("400", "", "Identity not authenticated"); - } + if ( + !authenticationPublicKey || + !window.loadedIdentities[authenticationPublicKey] || + !extendPinCodeTtl(authenticationPublicKey) + ) { + return encodeResponse("400", "", "Identity not authenticated"); + } - wopiAPI.getPassports(fileID).then(function(response) { - result(response.data); - }); - }); + const response = await wopiAPI.getPassports(fileId); + return response.data; }, - // TODO rewrite with async await - wopiPutFile: function (fileId, accessToken, file) { - return new Penpal.Promise(function(result) { - const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); - if ( - !authenticationPublicKey || - !window.loadedIdentities[authenticationPublicKey] || - !extendPinCodeTtl(authenticationPublicKey) - ) { - return encodeResponse("400", "", "Identity not authenticated"); - } + wopiPutFile: async (fileId, accessToken, file) => { + const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); - wopiAPI.putDocument(fileId, accessToken, file).then(function(response) { - result(response.data); - }); - }); + if ( + !authenticationPublicKey || + !window.loadedIdentities[authenticationPublicKey] || + !extendPinCodeTtl(authenticationPublicKey) + ) { + return encodeResponse("400", "", "Identity not authenticated"); + } + + const response = await wopiAPI.putDocument(fileId, accessToken, file); + return response.data; }, ...penpalMethods } diff --git a/javascript/src/iframe/wopiapi-iframe.js b/javascript/src/iframe/wopiapi-iframe.js index 3607cae..01639ea 100644 --- a/javascript/src/iframe/wopiapi-iframe.js +++ b/javascript/src/iframe/wopiapi-iframe.js @@ -39,7 +39,4 @@ WopiAPI.prototype.putDocument = function (fileId, accessToken, file) { return axios(requestConfig); }; -// TODO -// add put file - module.exports = WopiAPI; -- GitLab