diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-27 16:12:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-27 16:12:41 +0200 |
commit | 8f608a4cb22ab232cfab20665050764b38bac9c7 (patch) | |
tree | 6a6785aae79bf5939ad7b7a50a1bd8031268d2b4 /server/lib/client-html.ts | |
parent | 030ccfce59a8cb8f2fee6ea8dd363ba635c5c5c2 (diff) | |
parent | c215e627b575d2c4085ccb222f4ca8d0237b7552 (diff) | |
download | PeerTube-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.ts | 18 |
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' | |||
2 | import { readFile } from 'fs-extra' | 2 | import { readFile } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import validator from 'validator' | 4 | import validator from 'validator' |
5 | import { escapeHTML } from '@shared/core-utils/renderer' | ||
6 | import { HTMLServerConfig } from '@shared/models' | ||
5 | import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' | 7 | import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' |
6 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | 8 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' |
7 | import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' | 9 | import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' |
8 | import { isTestInstance, sha256 } from '../helpers/core-utils' | 10 | import { isTestInstance, sha256 } from '../helpers/core-utils' |
9 | import { escapeHTML } from '@shared/core-utils/renderer' | ||
10 | import { logger } from '../helpers/logger' | 11 | import { logger } from '../helpers/logger' |
12 | import { mdToPlainText } from '../helpers/markdown' | ||
11 | import { CONFIG } from '../initializers/config' | 13 | import { CONFIG } from '../initializers/config' |
12 | import { | 14 | import { |
13 | ACCEPT_HEADERS, | 15 | ACCEPT_HEADERS, |
@@ -24,7 +26,7 @@ import { VideoChannelModel } from '../models/video/video-channel' | |||
24 | import { getActivityStreamDuration } from '../models/video/video-format-utils' | 26 | import { getActivityStreamDuration } from '../models/video/video-format-utils' |
25 | import { VideoPlaylistModel } from '../models/video/video-playlist' | 27 | import { VideoPlaylistModel } from '../models/video/video-playlist' |
26 | import { MAccountActor, MChannelActor } from '../types/models' | 28 | import { MAccountActor, MChannelActor } from '../types/models' |
27 | import { mdToPlainText } from '../helpers/markdown' | 29 | import { ServerConfigManager } from './server-config-manager' |
28 | 30 | ||
29 | type Tags = { | 31 | type 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 |