aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/helpers/markdown.ts4
-rw-r--r--server/initializers/constants.ts4
-rw-r--r--server/lib/client-html.ts14
3 files changed, 16 insertions, 6 deletions
diff --git a/server/helpers/markdown.ts b/server/helpers/markdown.ts
index 25685ec6d..41c1186ec 100644
--- a/server/helpers/markdown.ts
+++ b/server/helpers/markdown.ts
@@ -8,7 +8,7 @@ const markdownItEmoji = require('markdown-it-emoji/light')
8const MarkdownItClass = require('markdown-it') 8const MarkdownItClass = require('markdown-it')
9 9
10const markdownItWithHTML = new MarkdownItClass('default', { linkify: true, breaks: true, html: true }) 10const markdownItWithHTML = new MarkdownItClass('default', { linkify: true, breaks: true, html: true })
11const markdownItWithoutHTML = new MarkdownItClass('default', { linkify: true, breaks: true, html: false }) 11const markdownItWithoutHTML = new MarkdownItClass('default', { linkify: false, breaks: true, html: false })
12 12
13const toSafeHtml = (text: string) => { 13const toSafeHtml = (text: string) => {
14 if (!text) return '' 14 if (!text) return ''
@@ -66,7 +66,7 @@ function plainTextPlugin (markdownIt: any) {
66 66
67 if (token.type === 'list_item_close') { 67 if (token.type === 'list_item_close') {
68 lastSeparator = ', ' 68 lastSeparator = ', '
69 } else if (/[a-zA-Z]+_close/.test(token.type)) { 69 } else if (token.type.endsWith('_close')) {
70 lastSeparator = ' ' 70 lastSeparator = ' '
71 } else if (token.content) { 71 } else if (token.content) {
72 text += lastSeparator 72 text += lastSeparator
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 4d2a6fc63..2367e7689 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -718,10 +718,12 @@ const MEMOIZE_TTL = {
718 OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours 718 OVERVIEWS_SAMPLE: 1000 * 3600 * 4, // 4 hours
719 INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours 719 INFO_HASH_EXISTS: 1000 * 3600 * 12, // 12 hours
720 LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute 720 LIVE_ABLE_TO_UPLOAD: 1000 * 60, // 1 minute
721 LIVE_CHECK_SOCKET_HEALTH: 1000 * 60 // 1 minute 721 LIVE_CHECK_SOCKET_HEALTH: 1000 * 60, // 1 minute
722 MD_TO_PLAIN_TEXT_CLIENT_HTML: 1000 * 60 // 1 minute
722} 723}
723 724
724const MEMOIZE_LENGTH = { 725const MEMOIZE_LENGTH = {
726 MD_TO_PLAIN_TEXT_CLIENT_HTML: 100,
725 INFO_HASH_EXISTS: 200 727 INFO_HASH_EXISTS: 200
726} 728}
727 729
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index c010f3c44..945bc712f 100644
--- a/server/lib/client-html.ts
+++ b/server/lib/client-html.ts
@@ -1,5 +1,6 @@
1import express from 'express' 1import express from 'express'
2import { readFile } from 'fs-extra' 2import { readFile } from 'fs-extra'
3import memoizee from 'memoizee'
3import { join } from 'path' 4import { join } from 'path'
4import validator from 'validator' 5import validator from 'validator'
5import { toCompleteUUID } from '@server/helpers/custom-validators/misc' 6import { toCompleteUUID } from '@server/helpers/custom-validators/misc'
@@ -20,6 +21,8 @@ import {
20 CUSTOM_HTML_TAG_COMMENTS, 21 CUSTOM_HTML_TAG_COMMENTS,
21 EMBED_SIZE, 22 EMBED_SIZE,
22 FILES_CONTENT_HASH, 23 FILES_CONTENT_HASH,
24 MEMOIZE_LENGTH,
25 MEMOIZE_TTL,
23 PLUGIN_GLOBAL_CSS_PATH, 26 PLUGIN_GLOBAL_CSS_PATH,
24 WEBSERVER 27 WEBSERVER
25} from '../initializers/constants' 28} from '../initializers/constants'
@@ -32,6 +35,11 @@ import { MAccountActor, MChannelActor } from '../types/models'
32import { getBiggestActorImage } from './actor-image' 35import { getBiggestActorImage } from './actor-image'
33import { ServerConfigManager } from './server-config-manager' 36import { ServerConfigManager } from './server-config-manager'
34 37
38const getPlainTextDescriptionCached = memoizee(mdToOneLinePlainText, {
39 maxAge: MEMOIZE_TTL.MD_TO_PLAIN_TEXT_CLIENT_HTML,
40 max: MEMOIZE_LENGTH.MD_TO_PLAIN_TEXT_CLIENT_HTML
41})
42
35type Tags = { 43type Tags = {
36 ogType: string 44 ogType: string
37 twitterCard: 'player' | 'summary' | 'summary_large_image' 45 twitterCard: 'player' | 'summary' | 'summary_large_image'
@@ -104,7 +112,7 @@ class ClientHtml {
104 res.status(HttpStatusCode.NOT_FOUND_404) 112 res.status(HttpStatusCode.NOT_FOUND_404)
105 return html 113 return html
106 } 114 }
107 const description = mdToOneLinePlainText(video.description) 115 const description = getPlainTextDescriptionCached(video.description)
108 116
109 let customHtml = ClientHtml.addTitleTag(html, video.name) 117 let customHtml = ClientHtml.addTitleTag(html, video.name)
110 customHtml = ClientHtml.addDescriptionTag(customHtml, description) 118 customHtml = ClientHtml.addDescriptionTag(customHtml, description)
@@ -165,7 +173,7 @@ class ClientHtml {
165 return html 173 return html
166 } 174 }
167 175
168 const description = mdToOneLinePlainText(videoPlaylist.description) 176 const description = getPlainTextDescriptionCached(videoPlaylist.description)
169 177
170 let customHtml = ClientHtml.addTitleTag(html, videoPlaylist.name) 178 let customHtml = ClientHtml.addTitleTag(html, videoPlaylist.name)
171 customHtml = ClientHtml.addDescriptionTag(customHtml, description) 179 customHtml = ClientHtml.addDescriptionTag(customHtml, description)
@@ -264,7 +272,7 @@ class ClientHtml {
264 return ClientHtml.getIndexHTML(req, res) 272 return ClientHtml.getIndexHTML(req, res)
265 } 273 }
266 274
267 const description = mdToOneLinePlainText(entity.description) 275 const description = getPlainTextDescriptionCached(entity.description)
268 276
269 let customHtml = ClientHtml.addTitleTag(html, entity.getDisplayName()) 277 let customHtml = ClientHtml.addTitleTag(html, entity.getDisplayName())
270 customHtml = ClientHtml.addDescriptionTag(customHtml, description) 278 customHtml = ClientHtml.addDescriptionTag(customHtml, description)