aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/emailer.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-17 14:34:09 +0100
committerChocobozzz <me@florianbigard.com>2020-11-17 14:34:09 +0100
commit9ff36c2d70956d2775d207c7809adb6fe7f2f2a5 (patch)
treec9058f8210d9674b69307c4f7c5ccde85a1ba597 /server/lib/emailer.ts
parent9afb5c10e5935e667e33219bdbd775e9ed1b4330 (diff)
downloadPeerTube-9ff36c2d70956d2775d207c7809adb6fe7f2f2a5.tar.gz
PeerTube-9ff36c2d70956d2775d207c7809adb6fe7f2f2a5.tar.zst
PeerTube-9ff36c2d70956d2775d207c7809adb6fe7f2f2a5.zip
Refactor markdown/sanitize html code
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r--server/lib/emailer.ts32
1 files changed, 3 insertions, 29 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index 40f278608..650a3c090 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -5,6 +5,7 @@ import { join } from 'path'
5import { VideoChannelModel } from '@server/models/video/video-channel' 5import { VideoChannelModel } from '@server/models/video/video-channel'
6import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist' 6import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist'
7import { MVideoImport, MVideoImportVideo } from '@server/types/models/video/video-import' 7import { MVideoImport, MVideoImportVideo } from '@server/types/models/video/video-import'
8import { SANITIZE_OPTIONS, TEXT_WITH_HTML_RULES } from '@shared/core-utils'
8import { AbuseState, EmailPayload, UserAbuse } from '@shared/models' 9import { AbuseState, EmailPayload, UserAbuse } from '@shared/models'
9import { SendEmailOptions } from '../../shared/models/server/emailer.model' 10import { SendEmailOptions } from '../../shared/models/server/emailer.model'
10import { isTestInstance, root } from '../helpers/core-utils' 11import { isTestInstance, root } from '../helpers/core-utils'
@@ -20,14 +21,7 @@ const markdownItEmoji = require('markdown-it-emoji/light')
20const MarkdownItClass = require('markdown-it') 21const MarkdownItClass = require('markdown-it')
21const markdownIt = new MarkdownItClass('default', { linkify: true, breaks: true, html: true }) 22const markdownIt = new MarkdownItClass('default', { linkify: true, breaks: true, html: true })
22 23
23markdownIt.enable([ 24markdownIt.enable(TEXT_WITH_HTML_RULES)
24 'linkify',
25 'autolink',
26 'emphasis',
27 'link',
28 'newline',
29 'list'
30])
31 25
32markdownIt.use(markdownItEmoji) 26markdownIt.use(markdownItEmoji)
33 27
@@ -39,27 +33,7 @@ const toSafeHtml = text => {
39 const html = markdownIt.render(textWithLineFeed) 33 const html = markdownIt.render(textWithLineFeed)
40 34
41 // Convert to safe Html 35 // Convert to safe Html
42 return sanitizeHtml(html, { 36 return sanitizeHtml(html, SANITIZE_OPTIONS)
43 allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ],
44 allowedSchemes: [ 'http', 'https' ],
45 allowedAttributes: {
46 a: [ 'href', 'class', 'target', 'rel' ]
47 },
48 transformTags: {
49 a: (tagName, attribs) => {
50 let rel = 'noopener noreferrer'
51 if (attribs.rel === 'me') rel += ' me'
52
53 return {
54 tagName,
55 attribs: Object.assign(attribs, {
56 target: '_blank',
57 rel
58 })
59 }
60 }
61 }
62 })
63} 37}
64 38
65const Email = require('email-templates') 39const Email = require('email-templates')