diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index b6d0af88fb6b75a2ce4d17e4422f444992b68d48..811b2420e8fc3e7500b98657134f921539614869 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -1074,9 +1074,49 @@ const connection = Penpal.connectToParent({ result(res) }) }, + + // Collabora APIs collaboraDiscovery() { 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"); + + if ( + !authenticationPublicKey || + !window.loadedIdentities[authenticationPublicKey] || + !extendPinCodeTtl(authenticationPublicKey) + ) { + return encodeResponse("400", "", "Identity not authenticated"); + } + + wopiAPI.getPassports(fileID).then(function(response) { + result(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"); + } + + wopiAPI.putDocument(fileId, accessToken, file).then(function(response) { + result(response.data); + }); + }); + }, ...penpalMethods } }); diff --git a/javascript/src/iframe/wopiapi-iframe.js b/javascript/src/iframe/wopiapi-iframe.js index 8d5b72aaab4722fc51f4167f93859253fa2901d1..3607cae34574aec2e2c03a1638c015663fb9dca0 100644 --- a/javascript/src/iframe/wopiapi-iframe.js +++ b/javascript/src/iframe/wopiapi-iframe.js @@ -19,4 +19,27 @@ WopiAPI.prototype.getPassports = function (fileID) { return axios(requestConfig); }; +WopiAPI.prototype.putDocument = function (fileId, accessToken, file) { + const { publicKey, uuid, token, deviceHash } = window.viamApi.getConfig().headers; + const requestConfig = { + url: `${window.WOPI_URL}files/${fileId}/contents`, + method: 'POST', + headers: { + publicKey, + uuid, + token, + deviceHash + }, + params: { + access_token: accessToken + }, + data: file + }; + + return axios(requestConfig); +}; + +// TODO +// add put file + module.exports = WopiAPI; diff --git a/main.go b/main.go index 83c19174e913fd9c85fc6850865bb00d58ea9d97..9403462640845335dbc98509fbdc893918aec8ac 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,6 @@ func buildPenpalMethods() string { "export default {\n" methods := generatePenpalRemoteMethods(endPoints) - methods += getWopiAPIPenpalMethods() result += methods @@ -79,7 +78,6 @@ func buildViamAPI() string { " }\n" + "}\n\n" - result += "ViamAPI.prototype.setSessionData = function(uuid, token) {\n" + " this.config.headers.uuid = uuid;\n" + " this.config.headers.token = token;\n" + @@ -621,12 +619,12 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string { } if endPoints[url].Url == "/document/createDocument" { - continue - } + continue + } - if endPoints[url].Url == "/document/putDocument" { - continue - } + if endPoints[url].Url == "/document/putDocument" { + continue + } if url == "/identity/getIdentityProfileData" { privateCheckSnippet = ` @@ -677,7 +675,6 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string { } } - snippet := "" if endPoints[url].HandlerType == "private" { @@ -739,39 +736,3 @@ func generatePenpalRemoteMethods(endPoints map[string]*server.EndPoint) string { return methods } - -func getWopiAPIPenpalMethods() string { - return `getPassports: function(fileID) { - return new Penpal.Promise(function(result) { - const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); - if (authenticationPublicKey === null) { - result({ - "data" : "", - "code" : "400", - "status" : "Identity not authenticated" - }); - } - - if (loadedIdentities[authenticationPublicKey] === null) { - result({ - "data" : "", - "code" : "400", - "status" : "Identity not authenticated" - }); - } - - const success = extendPinCodeTtl(authenticationPublicKey); - - if (success === false) { - result({"data" : "", - "code" : "400", - "status" : "Identity not authenticated" - }); - } - - wopiAPI.getPassports(fileID).then(function(response) { - result(response.data); - }); - }); - }` -}