mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-27 02:51:57 +02:00
[web] last features esm conversion GitOrigin-RevId: a35ab995bf654f1cdfe0e0062d8806761ecccf2d
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
import { callbackify } from 'node:util'
|
|
import Settings from '@overleaf/settings'
|
|
import logger from '@overleaf/logger'
|
|
import EmailBuilder from './EmailBuilder.mjs'
|
|
import EmailSender from './EmailSender.mjs'
|
|
import Queues from '../../infrastructure/Queues.mjs'
|
|
|
|
const EMAIL_SETTINGS = Settings.email || {}
|
|
|
|
/**
|
|
* @param {string} emailType
|
|
* @param {opts} any
|
|
*/
|
|
async function sendEmail(emailType, opts) {
|
|
const email = EmailBuilder.buildEmail(emailType, opts)
|
|
if (email.type === 'lifecycle' && !EMAIL_SETTINGS.lifecycle) {
|
|
return
|
|
}
|
|
opts.html = email.html
|
|
opts.text = email.text
|
|
opts.subject = email.subject
|
|
await EmailSender.promises.sendEmail(opts, emailType)
|
|
}
|
|
|
|
function sendDeferredEmail(emailType, opts, delay) {
|
|
Queues.createScheduledJob(
|
|
'deferred-emails',
|
|
{ data: { emailType, opts } },
|
|
delay
|
|
).catch(err => {
|
|
logger.warn({ err, emailType, opts }, 'failed to queue deferred email')
|
|
})
|
|
}
|
|
|
|
export default {
|
|
sendEmail: callbackify(sendEmail),
|
|
sendDeferredEmail,
|
|
promises: {
|
|
sendEmail,
|
|
},
|
|
}
|