diff options
Diffstat (limited to 'server/lib/client-html.ts')
-rw-r--r-- | server/lib/client-html.ts | 14 |
1 files changed, 11 insertions, 3 deletions
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 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { readFile } from 'fs-extra' | 2 | import { readFile } from 'fs-extra' |
3 | import memoizee from 'memoizee' | ||
3 | import { join } from 'path' | 4 | import { join } from 'path' |
4 | import validator from 'validator' | 5 | import validator from 'validator' |
5 | import { toCompleteUUID } from '@server/helpers/custom-validators/misc' | 6 | import { 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' | |||
32 | import { getBiggestActorImage } from './actor-image' | 35 | import { getBiggestActorImage } from './actor-image' |
33 | import { ServerConfigManager } from './server-config-manager' | 36 | import { ServerConfigManager } from './server-config-manager' |
34 | 37 | ||
38 | const 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 | |||
35 | type Tags = { | 43 | type 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) |