diff --git a/javascript/src/iframe/wopiapi-iframe.js b/javascript/src/iframe/wopiapi-iframe.js index 6e7794e5312f04a8716b0571ec0a99a057e75432..542042c3c460ffc1eb6683c2ba7b96be637a4481 100644 --- a/javascript/src/iframe/wopiapi-iframe.js +++ b/javascript/src/iframe/wopiapi-iframe.js @@ -1,3 +1,5 @@ +import {encodeResponse} from "../utilities/appUtility"; + const axios = require('axios'); function WopiAPI() {} @@ -20,6 +22,31 @@ WopiAPI.prototype.getPassports = function (resourceID, contentType) { return axios(requestConfig); }; +WopiAPI.prototype.createDocument = async (passportUUID, path, contentType, title) => { + const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); + if ( + !authenticationPublicKey || + !window.loadedIdentities[authenticationPublicKey] || + !extendPinCodeTtl(authenticationPublicKey) + ) { + return encodeResponse("400", "", "Identity not authenticated"); + } + + const config = { + headers: { + path, + passportuuid: passportUUID, + contentType, + title + } + }; + const response = await executeRestfulFunction("private", window.viamApi, window.viamApi.documentCreateDocument, + config); + + const resourceID = response.data; + return await this.getPassports(resourceID, contentType); +}; + WopiAPI.prototype.putDocument = function (resourceID, accessToken, file) { const { publicKey, uuid, token, deviceHash } = window.viamApi.getConfig().headers;