diff options
author | Chocobozzz <me@florianbigard.com> | 2021-03-12 10:22:17 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-03-24 18:18:41 +0100 |
commit | cae2df6bdc3c3590df32bf7431a617177be30429 (patch) | |
tree | f1f9680f7ca39454748302bf290c9ac01361a2f5 /server/lib | |
parent | 32a18cbf33a7cdbbe3d4885d32e4b67e19cdc1cf (diff) | |
download | PeerTube-cae2df6bdc3c3590df32bf7431a617177be30429.tar.gz PeerTube-cae2df6bdc3c3590df32bf7431a617177be30429.tar.zst PeerTube-cae2df6bdc3c3590df32bf7431a617177be30429.zip |
Stricter email options typings
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/emailer.ts | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 187d4e86d..ce4134d59 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts | |||
@@ -7,7 +7,7 @@ import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/m | |||
7 | import { MVideoImport, MVideoImportVideo } from '@server/types/models/video/video-import' | 7 | import { MVideoImport, MVideoImportVideo } from '@server/types/models/video/video-import' |
8 | import { SANITIZE_OPTIONS, TEXT_WITH_HTML_RULES } from '@shared/core-utils' | 8 | import { SANITIZE_OPTIONS, TEXT_WITH_HTML_RULES } from '@shared/core-utils' |
9 | import { AbuseState, EmailPayload, UserAbuse } from '@shared/models' | 9 | import { AbuseState, EmailPayload, UserAbuse } from '@shared/models' |
10 | import { SendEmailOptions } from '../../shared/models/server/emailer.model' | 10 | import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model' |
11 | import { isTestInstance, root } from '../helpers/core-utils' | 11 | import { isTestInstance, root } from '../helpers/core-utils' |
12 | import { bunyanLogger, logger } from '../helpers/logger' | 12 | import { bunyanLogger, logger } from '../helpers/logger' |
13 | import { CONFIG, isEmailEnabled } from '../initializers/config' | 13 | import { CONFIG, isEmailEnabled } from '../initializers/config' |
@@ -473,13 +473,10 @@ class Emailer { | |||
473 | } | 473 | } |
474 | 474 | ||
475 | addNewPeerTubeVersionNotification (to: string[], latestVersion: string) { | 475 | addNewPeerTubeVersionNotification (to: string[], latestVersion: string) { |
476 | const subject = `A new PeerTube version is available: ${latestVersion}` | ||
477 | |||
478 | const emailPayload: EmailPayload = { | 476 | const emailPayload: EmailPayload = { |
479 | to, | 477 | to, |
480 | template: 'peertube-version-new', | 478 | template: 'peertube-version-new', |
481 | subject, | 479 | subject: `A new PeerTube version is available: ${latestVersion}`, |
482 | text: subject, | ||
483 | locals: { | 480 | locals: { |
484 | latestVersion | 481 | latestVersion |
485 | } | 482 | } |
@@ -491,13 +488,10 @@ class Emailer { | |||
491 | addNewPlugionVersionNotification (to: string[], plugin: MPlugin) { | 488 | addNewPlugionVersionNotification (to: string[], plugin: MPlugin) { |
492 | const pluginUrl = WEBSERVER.URL + '/admin/plugins/list-installed?pluginType=' + plugin.type | 489 | const pluginUrl = WEBSERVER.URL + '/admin/plugins/list-installed?pluginType=' + plugin.type |
493 | 490 | ||
494 | const subject = `A new plugin/theme version is available: ${plugin.name}@${plugin.latestVersion}` | ||
495 | |||
496 | const emailPayload: EmailPayload = { | 491 | const emailPayload: EmailPayload = { |
497 | to, | 492 | to, |
498 | template: 'plugin-version-new', | 493 | template: 'plugin-version-new', |
499 | subject, | 494 | subject: `A new plugin/theme version is available: ${plugin.name}@${plugin.latestVersion}`, |
500 | text: subject, | ||
501 | locals: { | 495 | locals: { |
502 | pluginName: plugin.name, | 496 | pluginName: plugin.name, |
503 | latestVersion: plugin.latestVersion, | 497 | latestVersion: plugin.latestVersion, |
@@ -605,26 +599,27 @@ class Emailer { | |||
605 | }) | 599 | }) |
606 | 600 | ||
607 | for (const to of options.to) { | 601 | for (const to of options.to) { |
608 | await email | 602 | const baseOptions: SendEmailDefaultOptions = { |
609 | .send(merge( | 603 | template: 'common', |
610 | { | 604 | message: { |
611 | template: 'common', | 605 | to, |
612 | message: { | 606 | from: options.from, |
613 | to, | 607 | subject: options.subject, |
614 | from: options.from, | 608 | replyTo: options.replyTo |
615 | subject: options.subject, | 609 | }, |
616 | replyTo: options.replyTo | 610 | locals: { // default variables available in all templates |
617 | }, | 611 | WEBSERVER, |
618 | locals: { // default variables available in all templates | 612 | EMAIL: CONFIG.EMAIL, |
619 | WEBSERVER, | 613 | instanceName: CONFIG.INSTANCE.NAME, |
620 | EMAIL: CONFIG.EMAIL, | 614 | text: options.text, |
621 | instanceName: CONFIG.INSTANCE.NAME, | 615 | subject: options.subject |
622 | text: options.text, | 616 | } |
623 | subject: options.subject | 617 | } |
624 | } | 618 | |
625 | }, | 619 | // overriden/new variables given for a specific template in the payload |
626 | options // overriden/new variables given for a specific template in the payload | 620 | const sendOptions = merge(baseOptions, options) |
627 | ) as SendEmailOptions) | 621 | |
622 | await email.send(sendOptions) | ||
628 | .then(res => logger.debug('Sent email.', { res })) | 623 | .then(res => logger.debug('Sent email.', { res })) |
629 | .catch(err => logger.error('Error in email sender.', { err })) | 624 | .catch(err => logger.error('Error in email sender.', { err })) |
630 | } | 625 | } |