diff options
Diffstat (limited to 'server/lib/client-html.ts')
-rw-r--r-- | server/lib/client-html.ts | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 19354ab70..945bc712f 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts | |||
@@ -1,8 +1,10 @@ | |||
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' |
7 | import { ActorImageModel } from '@server/models/actor/actor-image' | ||
6 | import { root } from '@shared/core-utils' | 8 | import { root } from '@shared/core-utils' |
7 | import { escapeHTML } from '@shared/core-utils/renderer' | 9 | import { escapeHTML } from '@shared/core-utils/renderer' |
8 | import { sha256 } from '@shared/extra-utils' | 10 | import { sha256 } from '@shared/extra-utils' |
@@ -16,10 +18,11 @@ import { mdToOneLinePlainText } from '../helpers/markdown' | |||
16 | import { CONFIG } from '../initializers/config' | 18 | import { CONFIG } from '../initializers/config' |
17 | import { | 19 | import { |
18 | ACCEPT_HEADERS, | 20 | ACCEPT_HEADERS, |
19 | ACTOR_IMAGES_SIZE, | ||
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' |
@@ -29,8 +32,14 @@ import { VideoModel } from '../models/video/video' | |||
29 | import { VideoChannelModel } from '../models/video/video-channel' | 32 | import { VideoChannelModel } from '../models/video/video-channel' |
30 | import { VideoPlaylistModel } from '../models/video/video-playlist' | 33 | import { VideoPlaylistModel } from '../models/video/video-playlist' |
31 | import { MAccountActor, MChannelActor } from '../types/models' | 34 | import { MAccountActor, MChannelActor } from '../types/models' |
35 | import { getBiggestActorImage } from './actor-image' | ||
32 | import { ServerConfigManager } from './server-config-manager' | 36 | import { ServerConfigManager } from './server-config-manager' |
33 | 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 | |||
34 | type Tags = { | 43 | type Tags = { |
35 | ogType: string | 44 | ogType: string |
36 | twitterCard: 'player' | 'summary' | 'summary_large_image' | 45 | twitterCard: 'player' | 'summary' | 'summary_large_image' |
@@ -103,7 +112,7 @@ class ClientHtml { | |||
103 | res.status(HttpStatusCode.NOT_FOUND_404) | 112 | res.status(HttpStatusCode.NOT_FOUND_404) |
104 | return html | 113 | return html |
105 | } | 114 | } |
106 | const description = mdToOneLinePlainText(video.description) | 115 | const description = getPlainTextDescriptionCached(video.description) |
107 | 116 | ||
108 | let customHtml = ClientHtml.addTitleTag(html, video.name) | 117 | let customHtml = ClientHtml.addTitleTag(html, video.name) |
109 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) | 118 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) |
@@ -164,7 +173,7 @@ class ClientHtml { | |||
164 | return html | 173 | return html |
165 | } | 174 | } |
166 | 175 | ||
167 | const description = mdToOneLinePlainText(videoPlaylist.description) | 176 | const description = getPlainTextDescriptionCached(videoPlaylist.description) |
168 | 177 | ||
169 | let customHtml = ClientHtml.addTitleTag(html, videoPlaylist.name) | 178 | let customHtml = ClientHtml.addTitleTag(html, videoPlaylist.name) |
170 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) | 179 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) |
@@ -263,7 +272,7 @@ class ClientHtml { | |||
263 | return ClientHtml.getIndexHTML(req, res) | 272 | return ClientHtml.getIndexHTML(req, res) |
264 | } | 273 | } |
265 | 274 | ||
266 | const description = mdToOneLinePlainText(entity.description) | 275 | const description = getPlainTextDescriptionCached(entity.description) |
267 | 276 | ||
268 | let customHtml = ClientHtml.addTitleTag(html, entity.getDisplayName()) | 277 | let customHtml = ClientHtml.addTitleTag(html, entity.getDisplayName()) |
269 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) | 278 | customHtml = ClientHtml.addDescriptionTag(customHtml, description) |
@@ -273,10 +282,11 @@ class ClientHtml { | |||
273 | const siteName = CONFIG.INSTANCE.NAME | 282 | const siteName = CONFIG.INSTANCE.NAME |
274 | const title = entity.getDisplayName() | 283 | const title = entity.getDisplayName() |
275 | 284 | ||
285 | const avatar = getBiggestActorImage(entity.Actor.Avatars) | ||
276 | const image = { | 286 | const image = { |
277 | url: entity.Actor.getAvatarUrl(), | 287 | url: ActorImageModel.getImageUrl(avatar), |
278 | width: ACTOR_IMAGES_SIZE.AVATARS.width, | 288 | width: avatar?.width, |
279 | height: ACTOR_IMAGES_SIZE.AVATARS.height | 289 | height: avatar?.height |
280 | } | 290 | } |
281 | 291 | ||
282 | const ogType = 'website' | 292 | const ogType = 'website' |