diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index 0d75a882c4419a5113917950aca5feb50525317b..a0b90a2be7593e17476bd59cb0bb809799e023e5 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 3c5526a75e0168e3032375adb2bee27cb27d97a6..6e7794e5312f04a8716b0571ec0a99a057e75432 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,