1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 19:42:24 +02:00

add filter:email.template-path.result / filter:email.subject.result (#6876)

* add filter:email.template-path.result / filter:email.subject.result

closes #3392

* Remove juice

* Kill mock server

---------

Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
kontrollanten 2025-04-02 15:16:29 +02:00 committed by GitHub
parent e9f887323a
commit 75d7c2a9dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 98 additions and 7 deletions

View file

@ -6,11 +6,13 @@ import { readFileSync } from 'fs'
import merge from 'lodash-es/merge.js'
import { Transporter, createTransport } from 'nodemailer'
import { join } from 'path'
import pug from 'pug'
import { bunyanLogger, logger } from '../helpers/logger.js'
import { CONFIG, isEmailEnabled } from '../initializers/config.js'
import { WEBSERVER } from '../initializers/constants.js'
import { MRegistration, MUser, MUserExport, MUserImport } from '../types/models/index.js'
import { JobQueue } from './job-queue/index.js'
import { Hooks } from './plugins/hooks.js'
class Emailer {
@ -260,15 +262,29 @@ class Emailer {
{ selector: 'a', options: { hideLinkHrefIfSameAsText: true } }
]
},
render: async (view: string, locals: Record<string, string>) => {
if (view.split('/').pop() !== 'html') return undefined
const templatePath = await Hooks.wrapObject(
join(root(), 'dist', 'core', 'assets', 'email-templates', view + '.pug'),
'filter:email.template-path.result',
{ view }
)
const compiledTemplate = pug.compileFile(templatePath)
return compiledTemplate(locals)
},
message: {
from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`
},
transport: this.transporter,
views: {
root: join(root(), 'dist', 'core', 'assets', 'email-templates')
},
subjectPrefix: CONFIG.EMAIL.SUBJECT.PREFIX
})
const subject = await Hooks.wrapObject(
options.subject,
'filter:email.subject.result',
{ template: 'template' in options ? options.template : undefined }
)
const toEmails = arrayify(options.to)
@ -280,7 +296,7 @@ class Emailer {
message: {
to,
from: options.from,
subject: options.subject,
subject,
replyTo: options.replyTo
},
locals: { // default variables available in all templates
@ -288,7 +304,7 @@ class Emailer {
EMAIL: CONFIG.EMAIL,
instanceName: CONFIG.INSTANCE.NAME,
text: options.text,
subject: options.subject
subject
}
}