diff options
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r-- | server/lib/emailer.ts | 79 |
1 files changed, 55 insertions, 24 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 969eae77b..ce4134d59 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts | |||
@@ -7,12 +7,12 @@ 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' |
14 | import { WEBSERVER } from '../initializers/constants' | 14 | import { WEBSERVER } from '../initializers/constants' |
15 | import { MAbuseFull, MAbuseMessage, MAccountDefault, MActorFollowActors, MActorFollowFull, MUser } from '../types/models' | 15 | import { MAbuseFull, MAbuseMessage, MAccountDefault, MActorFollowActors, MActorFollowFull, MPlugin, MUser } from '../types/models' |
16 | import { MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../types/models/video' | 16 | import { MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../types/models/video' |
17 | import { JobQueue } from './job-queue' | 17 | import { JobQueue } from './job-queue' |
18 | 18 | ||
@@ -403,7 +403,7 @@ class Emailer { | |||
403 | } | 403 | } |
404 | 404 | ||
405 | async addVideoAutoBlacklistModeratorsNotification (to: string[], videoBlacklist: MVideoBlacklistLightVideo) { | 405 | async addVideoAutoBlacklistModeratorsNotification (to: string[], videoBlacklist: MVideoBlacklistLightVideo) { |
406 | const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' | 406 | const videoAutoBlacklistUrl = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' |
407 | const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() | 407 | const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() |
408 | const channel = (await VideoChannelModel.loadByIdAndPopulateAccount(videoBlacklist.Video.channelId)).toFormattedSummaryJSON() | 408 | const channel = (await VideoChannelModel.loadByIdAndPopulateAccount(videoBlacklist.Video.channelId)).toFormattedSummaryJSON() |
409 | 409 | ||
@@ -417,7 +417,7 @@ class Emailer { | |||
417 | videoName: videoBlacklist.Video.name, | 417 | videoName: videoBlacklist.Video.name, |
418 | action: { | 418 | action: { |
419 | text: 'Review autoblacklist', | 419 | text: 'Review autoblacklist', |
420 | url: VIDEO_AUTO_BLACKLIST_URL | 420 | url: videoAutoBlacklistUrl |
421 | } | 421 | } |
422 | } | 422 | } |
423 | } | 423 | } |
@@ -472,6 +472,36 @@ class Emailer { | |||
472 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | 472 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) |
473 | } | 473 | } |
474 | 474 | ||
475 | addNewPeerTubeVersionNotification (to: string[], latestVersion: string) { | ||
476 | const emailPayload: EmailPayload = { | ||
477 | to, | ||
478 | template: 'peertube-version-new', | ||
479 | subject: `A new PeerTube version is available: ${latestVersion}`, | ||
480 | locals: { | ||
481 | latestVersion | ||
482 | } | ||
483 | } | ||
484 | |||
485 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | ||
486 | } | ||
487 | |||
488 | addNewPlugionVersionNotification (to: string[], plugin: MPlugin) { | ||
489 | const pluginUrl = WEBSERVER.URL + '/admin/plugins/list-installed?pluginType=' + plugin.type | ||
490 | |||
491 | const emailPayload: EmailPayload = { | ||
492 | to, | ||
493 | template: 'plugin-version-new', | ||
494 | subject: `A new plugin/theme version is available: ${plugin.name}@${plugin.latestVersion}`, | ||
495 | locals: { | ||
496 | pluginName: plugin.name, | ||
497 | latestVersion: plugin.latestVersion, | ||
498 | pluginUrl | ||
499 | } | ||
500 | } | ||
501 | |||
502 | return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) | ||
503 | } | ||
504 | |||
475 | addPasswordResetEmailJob (username: string, to: string, resetPasswordUrl: string) { | 505 | addPasswordResetEmailJob (username: string, to: string, resetPasswordUrl: string) { |
476 | const emailPayload: EmailPayload = { | 506 | const emailPayload: EmailPayload = { |
477 | template: 'password-reset', | 507 | template: 'password-reset', |
@@ -569,26 +599,27 @@ class Emailer { | |||
569 | }) | 599 | }) |
570 | 600 | ||
571 | for (const to of options.to) { | 601 | for (const to of options.to) { |
572 | await email | 602 | const baseOptions: SendEmailDefaultOptions = { |
573 | .send(merge( | 603 | template: 'common', |
574 | { | 604 | message: { |
575 | template: 'common', | 605 | to, |
576 | message: { | 606 | from: options.from, |
577 | to, | 607 | subject: options.subject, |
578 | from: options.from, | 608 | replyTo: options.replyTo |
579 | subject: options.subject, | 609 | }, |
580 | replyTo: options.replyTo | 610 | locals: { // default variables available in all templates |
581 | }, | 611 | WEBSERVER, |
582 | locals: { // default variables available in all templates | 612 | EMAIL: CONFIG.EMAIL, |
583 | WEBSERVER, | 613 | instanceName: CONFIG.INSTANCE.NAME, |
584 | EMAIL: CONFIG.EMAIL, | 614 | text: options.text, |
585 | instanceName: CONFIG.INSTANCE.NAME, | 615 | subject: options.subject |
586 | text: options.text, | 616 | } |
587 | subject: options.subject | 617 | } |
588 | } | 618 | |
589 | }, | 619 | // overriden/new variables given for a specific template in the payload |
590 | options // overriden/new variables given for a specific template in the payload | 620 | const sendOptions = merge(baseOptions, options) |
591 | ) as SendEmailOptions) | 621 | |
622 | await email.send(sendOptions) | ||
592 | .then(res => logger.debug('Sent email.', { res })) | 623 | .then(res => logger.debug('Sent email.', { res })) |
593 | .catch(err => logger.error('Error in email sender.', { err })) | 624 | .catch(err => logger.error('Error in email sender.', { err })) |
594 | } | 625 | } |