Skip to content
Snippets Groups Projects
Commit 6ba70e5a authored by Damyan Mitev's avatar Damyan Mitev :beach:
Browse files

Move useful methods implementation in the core file

parent 91161c1b
No related branches found
No related tags found
2 merge requests!48269 implement workflow for signing already uploaded document dev,!47269 implement workflow for signing already uploaded document
......@@ -414,6 +414,60 @@ function getCertificateForPassport(passportUUID, internal) {
});
}
function stringToUtf8ByteArray(str) {
if (typeof str !== 'string') {
str = str.toString();
}
const res = Buffer.from(str, 'utf-8');
return res;
}
function utf8ByteArrayToString(ba) {
if (!Buffer.isBuffer(ba)) {
ba = Buffer.from(ba);
}
const res = ba.toString('utf-8');
return res;
}
function stringToUtf8Base64(str) {
if (!Buffer.isBuffer(str)) {
if (typeof str !== 'string') {
str = str.toString();
}
str = Buffer.from(str, 'utf-8');
}
const res = str.toString('base64');
return res;
}
function utf8Base64ToString(strBase64) {
if (!Buffer.isBuffer(strBase64)) {
if (typeof strBase64 !== 'string') {
strBase64 = strBase64.toString();
}
strBase64 = Buffer.from(strBase64, 'base64');
}
const res = strBase64.toString('utf-8');
return res;
}
function base64ToByteArray(strBase64) {
if (typeof strBase64 !== 'string') {
strBase64 = strBase64.toString();
}
const res = Buffer.from(strBase64, 'base64');
return res;
}
function byteArrayToBase64(ba) {
if (!Buffer.isBuffer(ba)) {
ba = Buffer.from(ba);
}
const res = ba.toString('base64');
return res;
}
const connection = Penpal.connectToParent({
// Methods child is exposing to parent
methods: {
......@@ -981,11 +1035,11 @@ const connection = Penpal.connectToParent({
return encodeResponse("400", "", downloadResponse.status);
}
const pdfRaw = await this.base64ToByteArray(downloadResponse.data);
const pdfRaw = base64ToByteArray(downloadResponse.data);
const signedPdf = await signPdf(pdfRaw, certificateOneTime, passportChain, privateKeyOneTime);
const signedPdfB64 = await this.byteArrayToBase64(signedPdf);
const signedPdfB64 = byteArrayToBase64(signedPdf);
const uploadResponse = await executeRestfulFunction(
"private", window.viamApi, window.viamApi.documentPutDocumentByUUID, null, documentUUID, pdfContentType, signedPdfB64);
......@@ -1124,64 +1178,34 @@ const connection = Penpal.connectToParent({
);
},
stringToUtf8ByteArray(str) {
if (typeof str !== 'string') {
str = str.toString()
}
let res = Buffer.from(str,'utf-8');
return new Penpal.Promise(result => {
result(res)
})
result(stringToUtf8ByteArray(str));
});
},
utf8ByteArrayToString(ba) {
if (!Buffer.isBuffer(ba)) {
ba = Buffer.from(ba)
}
let res = ba.toString('utf-8');
return new Penpal.Promise(result => {
result(res)
})
result(utf8ByteArrayToString(ba));
});
},
stringToUtf8Base64(str) {
if (!Buffer.isBuffer(str)) {
if (typeof str !== 'string') {
str = str.toString()
}
str = Buffer.from(str, 'utf-8')
}
let res = str.toString('base64');
return new Penpal.Promise(result => {
result(res)
})
result(stringToUtf8Base64(str));
});
},
utf8Base64ToString(strBase64) {
if (!Buffer.isBuffer(strBase64)) {
if (typeof strBase64 !== 'string') {
strBase64 = strBase64.toString()
}
strBase64 = Buffer.from(strBase64, 'base64')
}
let res = strBase64.toString('utf-8');
return new Penpal.Promise(result => {
result(res)
})
result(utf8Base64ToString(strBase64));
});
},
base64ToByteArray(strBase64) {
if (typeof strBase64 !== 'string') {
strBase64 = strBase64.toString()
}
let res = Buffer.from(strBase64, 'base64');
return new Penpal.Promise(result => {
result(res)
})
result(base64ToByteArray(strBase64));
});
},
byteArrayToBase64(ba) {
if (!Buffer.isBuffer(ba)) {
ba = Buffer.from(ba)
}
let res = ba.toString('base64');
return new Penpal.Promise(result => {
result(res)
})
result(byteArrayToBase64(ba));
});
},
// Collabora APIs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment