2
0

🐛 (sendEmail) Check if attachment is URL

This commit is contained in:
Baptiste Arnaud
2023-01-06 09:51:35 +01:00
parent b455078631
commit 7174ef0f81

View File

@ -6,7 +6,7 @@ import {
} from 'models' } from 'models'
import { NextApiRequest, NextApiResponse } from 'next' import { NextApiRequest, NextApiResponse } from 'next'
import { createTransport, getTestMessageUrl } from 'nodemailer' import { createTransport, getTestMessageUrl } from 'nodemailer'
import { isEmpty, isNotDefined, omit, parseAnswers } from 'utils' import { isDefined, isEmpty, isNotDefined, omit, parseAnswers } from 'utils'
import { methodNotAllowed, initMiddleware, decrypt } from 'utils/api' import { methodNotAllowed, initMiddleware, decrypt } from 'utils/api'
import { saveErrorLog, saveSuccessLog } from '@/features/logs/api' import { saveErrorLog, saveSuccessLog } from '@/features/logs/api'
@ -107,7 +107,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
to: recipients, to: recipients,
replyTo, replyTo,
subject, subject,
attachments: fileUrls?.split(', ').map((url) => ({ path: url })), attachments: fileUrls
?.split(', ')
.map((url) => (url.startsWith('http') ? { path: url } : undefined))
.filter(isDefined),
...emailBody, ...emailBody,
} }
try { try {