diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js index cf62bf4b9dcc0be361911a1c03f7aad5c417c0c1..3018b570cee8e98e6875f5bbed553132a7eedee6 100644 --- a/javascript/src/iframe/viamapi-iframe.js +++ b/javascript/src/iframe/viamapi-iframe.js @@ -897,6 +897,49 @@ const connection = Penpal.connectToParent({ return encodeResponse("200", response.data, "Email signed"); }, + createDocument: async (path, passportUUID, contenttype) => { + const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); + if ( + !authenticationPublicKey || + !window.loadedIdentities[authenticationPublicKey] || + !extendPinCodeTtl(authenticationPublicKey) + ) { + return encodeResponse("400", "", "Identity not authenticated"); + } + + const headers = window.viamApi.getConfig().headers; + headers.path = path; + headers.passportuuid = passportUUID; + headers.contenttype = contenttype; + + const response = await executeRestfulFunction( + "private", window.viamApi, window.viamApi.documentCreateDocument); + + return encodeResponse("200", response.data, "Document created"); + }, + putDocument: async (passportUUID, resourceid, file) => { + const authenticationPublicKey = localStorage.getItem("authenticatedIdentity"); + if ( + !authenticationPublicKey || + !window.loadedIdentities[authenticationPublicKey] || + !extendPinCodeTtl(authenticationPublicKey) + ) { + return encodeResponse("400", "", "Identity not authenticated"); + } + + const data = new FormData(); + data.append('file', file); + + const config = window.viamApi.getConfig(); + config.headers.passportuuid = passportUUID; + config.headers.resourceid = resourceid; + config.data = data; + + const response = await executeRestfulFunction( + "private", window.viamApi, window.viamApi.documentCreateDocument); + + return encodeResponse("200", response.data, "Document created"); + }, hasSession() { return new Penpal.Promise(result => { const authenticationPublicKey = localStorage.getItem("authenticatedIdentity");