Skip to content

Commit 941f3ac

Browse files
Merge pull request #1258 from OpenSignLabs/validation
fix: valid file is not attached to mail in signyourself flow
2 parents 55926e2 + 80d3200 commit 941f3ac

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

apps/OpenSign/src/components/pdf/EmailComponent.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ function EmailComponent({
3030
const pdfName = pdfDetails[0]?.Name;
3131
setIsLoading(true);
3232
let sendMail;
33+
34+
const docId = !pdfDetails?.[0]?.IsEnableOTP
35+
? pdfDetails?.[0]?.objectId
36+
: "";
37+
let presignedUrl = pdfUrl;
38+
try {
39+
// const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
40+
const axiosRes = await axios.post(
41+
`${localStorage.getItem("baseUrl")}/functions/getsignedurl`,
42+
{ url: pdfUrl, docId: docId },
43+
{
44+
headers: {
45+
"content-type": "Application/json",
46+
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
47+
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
48+
}
49+
}
50+
);
51+
presignedUrl = axiosRes.data.result;
52+
} catch (err) {
53+
console.log("err in getsignedurl", err);
54+
}
3355
for (let i = 0; i < emailList.length; i++) {
3456
try {
3557
const imgPng =
@@ -47,7 +69,7 @@ function EmailComponent({
4769
mailProvider: activeMailAdapter,
4870
extUserId: extUserId,
4971
pdfName: pdfName,
50-
url: pdfUrl,
72+
url: presignedUrl,
5173
recipient: emailList[i],
5274
subject: `${sender.name} has signed the doc - ${pdfName}`,
5375
from: sender.email,

apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,26 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
6868
type: 'application/pdf',
6969
path: './exports/certificate.pdf',
7070
};
71-
attachments = [file, certificate];
71+
if (fs.existsSync(certificate.path)) {
72+
attachments = [file, certificate];
73+
} else {
74+
attachments = [file];
75+
}
7276
} catch (err) {
7377
attachments = [file];
7478
console.log('Err in read certificate sendmailv3', err);
7579
}
7680
}
7781
const attachmentParts = attachments.map(attachment => {
78-
if (fs.existsSync(attachment.path)) {
79-
try {
80-
const content = fs.readFileSync(attachment.path);
81-
const encodedContent = content.toString('base64');
82-
return [
83-
`Content-Type: ${attachment.type}\n`,
84-
'MIME-Version: 1.0\n',
85-
`Content-Disposition: attachment; filename="${attachment.filename}"\n`,
86-
`Content-Transfer-Encoding: base64\n\n`,
87-
`${encodedContent}\n`,
88-
].join('');
89-
} catch (err) {
90-
console.log('Err in read attachments sendmailv3', attachment.path);
91-
}
92-
}
82+
const content = fs.readFileSync(attachment.path);
83+
const encodedContent = content.toString('base64');
84+
return [
85+
`Content-Type: ${attachment.type}\n`,
86+
'MIME-Version: 1.0\n',
87+
`Content-Disposition: attachment; filename="${attachment.filename}"\n`,
88+
`Content-Transfer-Encoding: base64\n\n`,
89+
`${encodedContent}\n`,
90+
].join('');
9391
});
9492

9593
const attachmentBody = attachmentParts.join(`\n--${boundary}\n`);
@@ -149,6 +147,14 @@ export default async function sendMailGmailProvider(_extRes, template) {
149147
},
150148
});
151149
console.log('gmail provider res: ', response?.status);
150+
const certificatePath = './exports/certificate.pdf';
151+
if (fs.existsSync(certificatePath)) {
152+
try {
153+
fs.unlinkSync(certificatePath);
154+
} catch (err) {
155+
console.log('Err in unlink certificate sendmailgmail provider');
156+
}
157+
}
152158
return { code: 200, message: 'Email sent successfully' };
153159
} catch (error) {
154160
console.error('Error sending email:', error);

0 commit comments

Comments
 (0)