aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/emailer.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-11 11:33:44 +0200
committerChocobozzz <me@florianbigard.com>2019-04-11 13:45:39 +0200
commit6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0 (patch)
treeb47de7efb8c6c611c63a15a971c6125a278f547a /server/lib/emailer.ts
parent2c3abc4fa796555eb7d25f416c4f41ab3e3ad8ca (diff)
downloadPeerTube-6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0.tar.gz
PeerTube-6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0.tar.zst
PeerTube-6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0.zip
Move config in its own file
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r--server/lib/emailer.ts43
1 files changed, 22 insertions, 21 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index aa9083362..8c06e9751 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -1,7 +1,7 @@
1import { createTransport, Transporter } from 'nodemailer' 1import { createTransport, Transporter } from 'nodemailer'
2import { isTestInstance } from '../helpers/core-utils' 2import { isTestInstance } from '../helpers/core-utils'
3import { bunyanLogger, logger } from '../helpers/logger' 3import { bunyanLogger, logger } from '../helpers/logger'
4import { CONFIG } from '../initializers' 4import { CONFIG } from '../initializers/config'
5import { UserModel } from '../models/account/user' 5import { UserModel } from '../models/account/user'
6import { VideoModel } from '../models/video/video' 6import { VideoModel } from '../models/video/video'
7import { JobQueue } from './job-queue' 7import { JobQueue } from './job-queue'
@@ -12,6 +12,7 @@ import { VideoAbuseModel } from '../models/video/video-abuse'
12import { VideoBlacklistModel } from '../models/video/video-blacklist' 12import { VideoBlacklistModel } from '../models/video/video-blacklist'
13import { VideoImportModel } from '../models/video/video-import' 13import { VideoImportModel } from '../models/video/video-import'
14import { ActorFollowModel } from '../models/activitypub/actor-follow' 14import { ActorFollowModel } from '../models/activitypub/actor-follow'
15import { WEBSERVER } from '../initializers/constants'
15 16
16type SendEmailOptions = { 17type SendEmailOptions = {
17 to: string[] 18 to: string[]
@@ -91,7 +92,7 @@ class Emailer {
91 92
92 addNewVideoFromSubscriberNotification (to: string[], video: VideoModel) { 93 addNewVideoFromSubscriberNotification (to: string[], video: VideoModel) {
93 const channelName = video.VideoChannel.getDisplayName() 94 const channelName = video.VideoChannel.getDisplayName()
94 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 95 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
95 96
96 const text = `Hi dear user,\n\n` + 97 const text = `Hi dear user,\n\n` +
97 `Your subscription ${channelName} just published a new video: ${video.name}` + 98 `Your subscription ${channelName} just published a new video: ${video.name}` +
@@ -148,7 +149,7 @@ class Emailer {
148 } 149 }
149 150
150 myVideoPublishedNotification (to: string[], video: VideoModel) { 151 myVideoPublishedNotification (to: string[], video: VideoModel) {
151 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 152 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
152 153
153 const text = `Hi dear user,\n\n` + 154 const text = `Hi dear user,\n\n` +
154 `Your video ${video.name} has been published.` + 155 `Your video ${video.name} has been published.` +
@@ -168,7 +169,7 @@ class Emailer {
168 } 169 }
169 170
170 myVideoImportSuccessNotification (to: string[], videoImport: VideoImportModel) { 171 myVideoImportSuccessNotification (to: string[], videoImport: VideoImportModel) {
171 const videoUrl = CONFIG.WEBSERVER.URL + videoImport.Video.getWatchStaticPath() 172 const videoUrl = WEBSERVER.URL + videoImport.Video.getWatchStaticPath()
172 173
173 const text = `Hi dear user,\n\n` + 174 const text = `Hi dear user,\n\n` +
174 `Your video import ${videoImport.getTargetIdentifier()} is finished.` + 175 `Your video import ${videoImport.getTargetIdentifier()} is finished.` +
@@ -188,7 +189,7 @@ class Emailer {
188 } 189 }
189 190
190 myVideoImportErrorNotification (to: string[], videoImport: VideoImportModel) { 191 myVideoImportErrorNotification (to: string[], videoImport: VideoImportModel) {
191 const importUrl = CONFIG.WEBSERVER.URL + '/my-account/video-imports' 192 const importUrl = WEBSERVER.URL + '/my-account/video-imports'
192 193
193 const text = `Hi dear user,\n\n` + 194 const text = `Hi dear user,\n\n` +
194 `Your video import ${videoImport.getTargetIdentifier()} encountered an error.` + 195 `Your video import ${videoImport.getTargetIdentifier()} encountered an error.` +
@@ -210,7 +211,7 @@ class Emailer {
210 addNewCommentOnMyVideoNotification (to: string[], comment: VideoCommentModel) { 211 addNewCommentOnMyVideoNotification (to: string[], comment: VideoCommentModel) {
211 const accountName = comment.Account.getDisplayName() 212 const accountName = comment.Account.getDisplayName()
212 const video = comment.Video 213 const video = comment.Video
213 const commentUrl = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath() 214 const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath()
214 215
215 const text = `Hi dear user,\n\n` + 216 const text = `Hi dear user,\n\n` +
216 `A new comment has been posted by ${accountName} on your video ${video.name}` + 217 `A new comment has been posted by ${accountName} on your video ${video.name}` +
@@ -232,7 +233,7 @@ class Emailer {
232 addNewCommentMentionNotification (to: string[], comment: VideoCommentModel) { 233 addNewCommentMentionNotification (to: string[], comment: VideoCommentModel) {
233 const accountName = comment.Account.getDisplayName() 234 const accountName = comment.Account.getDisplayName()
234 const video = comment.Video 235 const video = comment.Video
235 const commentUrl = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath() 236 const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath()
236 237
237 const text = `Hi dear user,\n\n` + 238 const text = `Hi dear user,\n\n` +
238 `${accountName} mentioned you on video ${video.name}` + 239 `${accountName} mentioned you on video ${video.name}` +
@@ -252,10 +253,10 @@ class Emailer {
252 } 253 }
253 254
254 addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) { 255 addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) {
255 const videoUrl = CONFIG.WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() 256 const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath()
256 257
257 const text = `Hi,\n\n` + 258 const text = `Hi,\n\n` +
258 `${CONFIG.WEBSERVER.HOST} received an abuse for the following video ${videoUrl}\n\n` + 259 `${WEBSERVER.HOST} received an abuse for the following video ${videoUrl}\n\n` +
259 `Cheers,\n` + 260 `Cheers,\n` +
260 `PeerTube.` 261 `PeerTube.`
261 262
@@ -269,8 +270,8 @@ class Emailer {
269 } 270 }
270 271
271 addVideoAutoBlacklistModeratorsNotification (to: string[], video: VideoModel) { 272 addVideoAutoBlacklistModeratorsNotification (to: string[], video: VideoModel) {
272 const VIDEO_AUTO_BLACKLIST_URL = CONFIG.WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' 273 const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list'
273 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 274 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
274 275
275 const text = `Hi,\n\n` + 276 const text = `Hi,\n\n` +
276 `A recently added video was auto-blacklisted and requires moderator review before publishing.` + 277 `A recently added video was auto-blacklisted and requires moderator review before publishing.` +
@@ -293,13 +294,13 @@ class Emailer {
293 294
294 addNewUserRegistrationNotification (to: string[], user: UserModel) { 295 addNewUserRegistrationNotification (to: string[], user: UserModel) {
295 const text = `Hi,\n\n` + 296 const text = `Hi,\n\n` +
296 `User ${user.username} just registered on ${CONFIG.WEBSERVER.HOST} PeerTube instance.\n\n` + 297 `User ${user.username} just registered on ${WEBSERVER.HOST} PeerTube instance.\n\n` +
297 `Cheers,\n` + 298 `Cheers,\n` +
298 `PeerTube.` 299 `PeerTube.`
299 300
300 const emailPayload: EmailPayload = { 301 const emailPayload: EmailPayload = {
301 to, 302 to,
302 subject: '[PeerTube] New user registration on ' + CONFIG.WEBSERVER.HOST, 303 subject: '[PeerTube] New user registration on ' + WEBSERVER.HOST,
303 text 304 text
304 } 305 }
305 306
@@ -308,10 +309,10 @@ class Emailer {
308 309
309 addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) { 310 addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) {
310 const videoName = videoBlacklist.Video.name 311 const videoName = videoBlacklist.Video.name
311 const videoUrl = CONFIG.WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() 312 const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath()
312 313
313 const reasonString = videoBlacklist.reason ? ` for the following reason: ${videoBlacklist.reason}` : '' 314 const reasonString = videoBlacklist.reason ? ` for the following reason: ${videoBlacklist.reason}` : ''
314 const blockedString = `Your video ${videoName} (${videoUrl} on ${CONFIG.WEBSERVER.HOST} has been blacklisted${reasonString}.` 315 const blockedString = `Your video ${videoName} (${videoUrl} on ${WEBSERVER.HOST} has been blacklisted${reasonString}.`
315 316
316 const text = 'Hi,\n\n' + 317 const text = 'Hi,\n\n' +
317 blockedString + 318 blockedString +
@@ -329,10 +330,10 @@ class Emailer {
329 } 330 }
330 331
331 addVideoUnblacklistNotification (to: string[], video: VideoModel) { 332 addVideoUnblacklistNotification (to: string[], video: VideoModel) {
332 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 333 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
333 334
334 const text = 'Hi,\n\n' + 335 const text = 'Hi,\n\n' +
335 `Your video ${video.name} (${videoUrl}) on ${CONFIG.WEBSERVER.HOST} has been unblacklisted.` + 336 `Your video ${video.name} (${videoUrl}) on ${WEBSERVER.HOST} has been unblacklisted.` +
336 '\n\n' + 337 '\n\n' +
337 'Cheers,\n' + 338 'Cheers,\n' +
338 `PeerTube.` 339 `PeerTube.`
@@ -348,7 +349,7 @@ class Emailer {
348 349
349 addPasswordResetEmailJob (to: string, resetPasswordUrl: string) { 350 addPasswordResetEmailJob (to: string, resetPasswordUrl: string) {
350 const text = `Hi dear user,\n\n` + 351 const text = `Hi dear user,\n\n` +
351 `A reset password procedure for your account ${to} has been requested on ${CONFIG.WEBSERVER.HOST} ` + 352 `A reset password procedure for your account ${to} has been requested on ${WEBSERVER.HOST} ` +
352 `Please follow this link to reset it: ${resetPasswordUrl}\n\n` + 353 `Please follow this link to reset it: ${resetPasswordUrl}\n\n` +
353 `If you are not the person who initiated this request, please ignore this email.\n\n` + 354 `If you are not the person who initiated this request, please ignore this email.\n\n` +
354 `Cheers,\n` + 355 `Cheers,\n` +
@@ -365,7 +366,7 @@ class Emailer {
365 366
366 addVerifyEmailJob (to: string, verifyEmailUrl: string) { 367 addVerifyEmailJob (to: string, verifyEmailUrl: string) {
367 const text = `Welcome to PeerTube,\n\n` + 368 const text = `Welcome to PeerTube,\n\n` +
368 `To start using PeerTube on ${CONFIG.WEBSERVER.HOST} you must verify your email! ` + 369 `To start using PeerTube on ${WEBSERVER.HOST} you must verify your email! ` +
369 `Please follow this link to verify this email belongs to you: ${verifyEmailUrl}\n\n` + 370 `Please follow this link to verify this email belongs to you: ${verifyEmailUrl}\n\n` +
370 `If you are not the person who initiated this request, please ignore this email.\n\n` + 371 `If you are not the person who initiated this request, please ignore this email.\n\n` +
371 `Cheers,\n` + 372 `Cheers,\n` +
@@ -383,7 +384,7 @@ class Emailer {
383 addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) { 384 addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) {
384 const reasonString = reason ? ` for the following reason: ${reason}` : '' 385 const reasonString = reason ? ` for the following reason: ${reason}` : ''
385 const blockedWord = blocked ? 'blocked' : 'unblocked' 386 const blockedWord = blocked ? 'blocked' : 'unblocked'
386 const blockedString = `Your account ${user.username} on ${CONFIG.WEBSERVER.HOST} has been ${blockedWord}${reasonString}.` 387 const blockedString = `Your account ${user.username} on ${WEBSERVER.HOST} has been ${blockedWord}${reasonString}.`
387 388
388 const text = 'Hi,\n\n' + 389 const text = 'Hi,\n\n' +
389 blockedString + 390 blockedString +
@@ -428,7 +429,7 @@ class Emailer {
428 429
429 const fromDisplayName = options.fromDisplayName 430 const fromDisplayName = options.fromDisplayName
430 ? options.fromDisplayName 431 ? options.fromDisplayName
431 : CONFIG.WEBSERVER.HOST 432 : WEBSERVER.HOST
432 433
433 return this.transporter.sendMail({ 434 return this.transporter.sendMail({
434 from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`, 435 from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`,