aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/client-html.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-27 16:12:41 +0200
committerChocobozzz <me@florianbigard.com>2021-05-27 16:12:41 +0200
commit8f608a4cb22ab232cfab20665050764b38bac9c7 (patch)
tree6a6785aae79bf5939ad7b7a50a1bd8031268d2b4 /server/lib/client-html.ts
parent030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2 (diff)
parentc215e627b575d2c4085ccb222f4ca8d0237b7552 (diff)
downloadPeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.tar.gz
PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.tar.zst
PeerTube-8f608a4cb22ab232cfab20665050764b38bac9c7.zip
Merge branch 'develop' into shorter-URLs-channels-accounts
Diffstat (limited to 'server/lib/client-html.ts')
-rw-r--r--server/lib/client-html.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index cac9edb30..2f6bce1c7 100644
--- a/server/lib/client-html.ts
+++ b/server/lib/client-html.ts
@@ -2,12 +2,14 @@ import * as express from 'express'
2import { readFile } from 'fs-extra' 2import { readFile } from 'fs-extra'
3import { join } from 'path' 3import { join } from 'path'
4import validator from 'validator' 4import validator from 'validator'
5import { escapeHTML } from '@shared/core-utils/renderer'
6import { HTMLServerConfig } from '@shared/models'
5import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' 7import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n'
6import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' 8import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
7import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' 9import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos'
8import { isTestInstance, sha256 } from '../helpers/core-utils' 10import { isTestInstance, sha256 } from '../helpers/core-utils'
9import { escapeHTML } from '@shared/core-utils/renderer'
10import { logger } from '../helpers/logger' 11import { logger } from '../helpers/logger'
12import { mdToPlainText } from '../helpers/markdown'
11import { CONFIG } from '../initializers/config' 13import { CONFIG } from '../initializers/config'
12import { 14import {
13 ACCEPT_HEADERS, 15 ACCEPT_HEADERS,
@@ -24,7 +26,7 @@ import { VideoChannelModel } from '../models/video/video-channel'
24import { getActivityStreamDuration } from '../models/video/video-format-utils' 26import { getActivityStreamDuration } from '../models/video/video-format-utils'
25import { VideoPlaylistModel } from '../models/video/video-playlist' 27import { VideoPlaylistModel } from '../models/video/video-playlist'
26import { MAccountActor, MChannelActor } from '../types/models' 28import { MAccountActor, MChannelActor } from '../types/models'
27import { mdToPlainText } from '../helpers/markdown' 29import { ServerConfigManager } from './server-config-manager'
28 30
29type Tags = { 31type Tags = {
30 ogType: string 32 ogType: string
@@ -222,11 +224,14 @@ class ClientHtml {
222 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] 224 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path]
223 225
224 const buffer = await readFile(path) 226 const buffer = await readFile(path)
227 const serverConfig = await ServerConfigManager.Instance.getHTMLServerConfig()
225 228
226 let html = buffer.toString() 229 let html = buffer.toString()
227 html = await ClientHtml.addAsyncPluginCSS(html) 230 html = await ClientHtml.addAsyncPluginCSS(html)
228 html = ClientHtml.addCustomCSS(html) 231 html = ClientHtml.addCustomCSS(html)
229 html = ClientHtml.addTitleTag(html) 232 html = ClientHtml.addTitleTag(html)
233 html = ClientHtml.addDescriptionTag(html)
234 html = ClientHtml.addServerConfig(html, serverConfig)
230 235
231 ClientHtml.htmlCache[path] = html 236 ClientHtml.htmlCache[path] = html
232 237
@@ -288,6 +293,7 @@ class ClientHtml {
288 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] 293 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path]
289 294
290 const buffer = await readFile(path) 295 const buffer = await readFile(path)
296 const serverConfig = await ServerConfigManager.Instance.getHTMLServerConfig()
291 297
292 let html = buffer.toString() 298 let html = buffer.toString()
293 299
@@ -296,6 +302,7 @@ class ClientHtml {
296 html = ClientHtml.addFaviconContentHash(html) 302 html = ClientHtml.addFaviconContentHash(html)
297 html = ClientHtml.addLogoContentHash(html) 303 html = ClientHtml.addLogoContentHash(html)
298 html = ClientHtml.addCustomCSS(html) 304 html = ClientHtml.addCustomCSS(html)
305 html = ClientHtml.addServerConfig(html, serverConfig)
299 html = await ClientHtml.addAsyncPluginCSS(html) 306 html = await ClientHtml.addAsyncPluginCSS(html)
300 307
301 ClientHtml.htmlCache[path] = html 308 ClientHtml.htmlCache[path] = html
@@ -368,6 +375,13 @@ class ClientHtml {
368 return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.CUSTOM_CSS, styleTag) 375 return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.CUSTOM_CSS, styleTag)
369 } 376 }
370 377
378 private static addServerConfig (htmlStringPage: string, serverConfig: HTMLServerConfig) {
379 const serverConfigString = JSON.stringify(serverConfig)
380 const configScriptTag = `<script type="application/javascript">window.PeerTubeServerConfig = '${serverConfigString}'</script>`
381
382 return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.SERVER_CONFIG, configScriptTag)
383 }
384
371 private static async addAsyncPluginCSS (htmlStringPage: string) { 385 private static async addAsyncPluginCSS (htmlStringPage: string) {
372 const globalCSSContent = await readFile(PLUGIN_GLOBAL_CSS_PATH) 386 const globalCSSContent = await readFile(PLUGIN_GLOBAL_CSS_PATH)
373 if (globalCSSContent.byteLength === 0) return htmlStringPage 387 if (globalCSSContent.byteLength === 0) return htmlStringPage