From 8539f6b685a51c9150ff2cd861f51e30f9f2151e Mon Sep 17 00:00:00 2001 From: Damyan Mitev <damyan.mitev@vereign.com> Date: Mon, 27 May 2019 17:28:27 +0300 Subject: [PATCH] refactor putDocument to use resourceId and contentType --- javascript/src/iframe/viamapi-iframe.js | 30 ++++++++++++++++++++++--- javascript/src/iframe/wopiapi-iframe.js | 9 ++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 0d75a88..a0b90a2 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -1097,7 +1097,7 @@ const connection = Penpal.connectToParent({ return encodeResponse("200", response.data, "Document created"); }, - documentPutDocument: async (passportUUID, resourceid, file) => { + documentPutDocument: async (passportUUID, resourceid, contentType, file) => { const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); if ( !authenticationPublicKey || @@ -1111,14 +1111,38 @@ const connection = Penpal.connectToParent({ headers: { 'Content-Type': 'multipart/form-data', passportuuid: passportUUID, - resourceid + resourceid, + contentType } }; const response = await executeRestfulFunction( "private", window.viamApi, window.viamApi.documentPutDocument, config, file); - return encodeResponse("200", response.data, "Document created"); + return encodeResponse("200", response.data, "Document stored"); + }, + documentGetDocument: async (passportUUID, resourceid, contentType) => { + const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); + if ( + !authenticationPublicKey || + !window.loadedIdentities[authenticationPublicKey] || + !extendPinCodeTtl(authenticationPublicKey) + ) { + return encodeResponse("400", "", "Identity not authenticated"); + } + + const config = { + headers: { + passportuuid: passportUUID, + resourceid, + contentType + } + }; + + const response = await executeRestfulFunction( + "private", window.viamApi, window.viamApi.documentGetDocument, config); + + return encodeResponse("200", response.data, "Document retrieved"); }, hasSession() { return new Penpal.Promise(result => { diff --git a/javascript/src/iframe/wopiapi-iframe.js b/javascript/src/iframe/wopiapi-iframe.js index 3c5526a..6e7794e 100644 --- a/javascript/src/iframe/wopiapi-iframe.js +++ b/javascript/src/iframe/wopiapi-iframe.js @@ -20,13 +20,12 @@ WopiAPI.prototype.getPassports = function (resourceID, contentType) { return axios(requestConfig); }; -//TODO rewrite put document to use resourceID and contentType -WopiAPI.prototype.putDocument = function (path, accessToken, file) { +WopiAPI.prototype.putDocument = function (resourceID, accessToken, file) { const { publicKey, uuid, token, deviceHash } = window.viamApi.getConfig().headers; - path = path[0] === "/" ? path : `/${path}`; - path = encodeURI(path); + + resourceID = encodeURI(resourceID); const requestConfig = { - url: `${window.WOPI_URL}files${path}/contents`, + url: `${window.WOPI_URL}files/${resourceID}/contents`, method: 'POST', headers: { publicKey, -- GitLab