diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 811b2420e8fc3e7500b98657134f921539614869..bf62ba1ad47c6c3ea473df8b8457b9a05301823b 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 3607cae34574aec2e2c03a1638c015663fb9dca0..01639ea057ebcf675babe1b99d416248f05be473 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;