Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 61 additions & 53 deletions apps/OpenSignServer/cloud/parsefunction/pdf/PDF.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,55 +92,62 @@ async function sendCompletedMail(e) {
},
});
}
async function sendDoctoWebhook(t, e) {
t.data.ExtUserPtr?.Webhook &&
((e = {
File: e || '',
Name: t?.data?.Name,
Note: t?.data?.Note || '',
Description: t?.data?.Description || '',
Signers: t?.data?.Signers?.map(e => ({ Name: e.Name, Email: e.Email, Phone: e.Phone })) || [
async function sendDoctoWebhook(t, e, a, s) {
let r = [];
(r = s
? { Name: s?.Name, Email: s?.Email, Phone: s?.Phone }
: t?.data?.Signers?.map(e => ({ Name: e.Name, Email: e.Email, Phone: e.Phone })) || [
{
Name: t?.data?.ExtUserPtr?.Name,
Email: t?.data?.ExtUserPtr?.Email,
Phone: t?.data?.ExtUserPtr?.Phone,
},
],
Event: 'Completed',
CompletedAt: new Date(),
CreatedAt: t?.data?.createdAt,
}),
await axios
.post(t?.data?.ExtUserPtr?.Webhook, e, { headers: { 'Content-Type': 'application/json' } })
.then(e => {
try {
var a = new Parse.Object('contracts_Webhook');
a.set('Log', e?.status),
a.set('UserId', {
__type: 'Pointer',
className: '_User',
objectId: t.data.ExtUserPtr.UserId.objectId,
}),
a.save(null, { useMasterKey: !0 });
} catch (e) {
console.log('err save in contracts_Webhook', e);
}
})
.catch(e => {
console.log('Err send data to webhook', e);
try {
var a = new Parse.Object('contracts_Webhook');
a.set('Log', e?.status),
a.set('UserId', {
__type: 'Pointer',
className: '_User',
objectId: t.data.ExtUserPtr.UserId.objectId,
}),
a.save(null, { useMasterKey: !0 });
} catch (e) {
console.log('err save in contracts_Webhook', e);
}
}));
]),
t.data.ExtUserPtr?.Webhook &&
((s =
'Signed' === a
? { Signer: r, SignedAt: new Date() }
: { Signers: r, CompletedAt: new Date() }),
(a = {
Event: a,
File: e || '',
Name: t?.data?.Name,
Note: t?.data?.Note || '',
Description: t?.data?.Description || '',
...s,
CreatedAt: t?.data?.createdAt,
}),
await axios
.post(t?.data?.ExtUserPtr?.Webhook, a, { headers: { 'Content-Type': 'application/json' } })
.then(e => {
try {
var a = new Parse.Object('contracts_Webhook');
a.set('Log', e?.status),
a.set('UserId', {
__type: 'Pointer',
className: '_User',
objectId: t.data.ExtUserPtr.UserId.objectId,
}),
a.save(null, { useMasterKey: !0 });
} catch (e) {
console.log('err save in contracts_Webhook', e);
}
})
.catch(e => {
console.log('Err send data to webhook', e);
try {
var a = new Parse.Object('contracts_Webhook');
a.set('Log', e?.status),
a.set('UserId', {
__type: 'Pointer',
className: '_User',
objectId: t.data.ExtUserPtr.UserId.objectId,
}),
a.save(null, { useMasterKey: !0 });
} catch (e) {
console.log('err save in contracts_Webhook', e);
}
}));
}
async function PDF(i, o) {
try {
Expand Down Expand Up @@ -221,8 +228,8 @@ async function PDF(i, o) {
);
var P,
v,
x = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`,
b = './exports/' + x,
b = `exported_file_${Math.floor(5e3 * Math.random())}.pdf`,
x = './exports/' + b,
U =
(t
? ((P = n.data.Signers?.map(e => e.Name + ' <' + e.Email + '>')),
Expand All @@ -241,9 +248,9 @@ async function PDF(i, o) {
signatureLength: 1e4,
})),
(v = await new SignPDF(e, u).signPDF()),
fs.writeFileSync(b, v))
: fs.writeFileSync(b, e),
await uploadFile(x, b));
fs.writeFileSync(x, v))
: fs.writeFileSync(x, e),
await uploadFile(b, x));
if (U && U.imageUrl) {
const o = await updateDoc(
i.params.docId,
Expand All @@ -260,17 +267,18 @@ async function PDF(i, o) {
pdfName: n.data.Name,
receiver: g,
}),
sendDoctoWebhook(n, U.imageUrl, 'Signed', s?.data.results?.[0]),
o &&
o.isCompleted &&
(sendCompletedMail({
url: U.imageUrl,
sender: { Mail: n.data.ExtUserPtr.Email, Name: 'Open sign' },
sender: { Mail: n.data.ExtUserPtr.Email, Name: 'OpenSign™' },
pdfName: n.data.Name,
receiver: n.data.ExtUserPtr.Email,
}),
sendDoctoWebhook(n, U.imageUrl)),
fs.unlinkSync(b),
console.log('New Signed PDF created called: ' + b),
sendDoctoWebhook(n, U.imageUrl, 'Completed')),
fs.unlinkSync(x),
console.log('New Signed PDF created called: ' + x),
'success' === o.message
? { status: 'success', data: U.imageUrl }
: { status: 'error', message: 'please provide required parameters!' }
Expand Down
Loading