aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/client-html.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/client-html.ts')
-rw-r--r--server/lib/client-html.ts24
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 @@
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'
7import { ActorImageModel } from '@server/models/actor/actor-image'
6import { root } from '@shared/core-utils' 8import { root } from '@shared/core-utils'
7import { escapeHTML } from '@shared/core-utils/renderer' 9import { escapeHTML } from '@shared/core-utils/renderer'
8import { sha256 } from '@shared/extra-utils' 10import { sha256 } from '@shared/extra-utils'
@@ -16,10 +18,11 @@ import { mdToOneLinePlainText } from '../helpers/markdown'
16import { CONFIG } from '../initializers/config' 18import { CONFIG } from '../initializers/config'
17import { 19import {
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'
29import { VideoChannelModel } from '../models/video/video-channel' 32import { VideoChannelModel } from '../models/video/video-channel'
30import { VideoPlaylistModel } from '../models/video/video-playlist' 33import { VideoPlaylistModel } from '../models/video/video-playlist'
31import { MAccountActor, MChannelActor } from '../types/models' 34import { MAccountActor, MChannelActor } from '../types/models'
35import { getBiggestActorImage } from './actor-image'
32import { ServerConfigManager } from './server-config-manager' 36import { ServerConfigManager } from './server-config-manager'
33 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
34type Tags = { 43type 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'