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.ts33
1 files changed, 29 insertions, 4 deletions
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index 203bd3893..3c09332b5 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
@@ -196,11 +198,22 @@ class ClientHtml {
196 } 198 }
197 199
198 static async getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) { 200 static async getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
199 return this.getAccountOrChannelHTMLPage(() => AccountModel.loadByNameWithHost(nameWithHost), req, res) 201 const accountModelPromise = AccountModel.loadByNameWithHost(nameWithHost)
202 return this.getAccountOrChannelHTMLPage(() => accountModelPromise, req, res)
200 } 203 }
201 204
202 static async getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) { 205 static async getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
203 return this.getAccountOrChannelHTMLPage(() => VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost), req, res) 206 const videoChannelModelPromise = VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost)
207 return this.getAccountOrChannelHTMLPage(() => videoChannelModelPromise, req, res)
208 }
209
210 static async getActorHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
211 const [ account, channel ] = await Promise.all([
212 AccountModel.loadByNameWithHost(nameWithHost),
213 VideoChannelModel.loadByNameWithHostAndPopulateAccount(nameWithHost)
214 ])
215
216 return this.getAccountOrChannelHTMLPage(() => Promise.resolve(account || channel), req, res)
204 } 217 }
205 218
206 static async getEmbedHTML () { 219 static async getEmbedHTML () {
@@ -209,11 +222,14 @@ class ClientHtml {
209 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] 222 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path]
210 223
211 const buffer = await readFile(path) 224 const buffer = await readFile(path)
225 const serverConfig = await ServerConfigManager.Instance.getHTMLServerConfig()
212 226
213 let html = buffer.toString() 227 let html = buffer.toString()
214 html = await ClientHtml.addAsyncPluginCSS(html) 228 html = await ClientHtml.addAsyncPluginCSS(html)
215 html = ClientHtml.addCustomCSS(html) 229 html = ClientHtml.addCustomCSS(html)
216 html = ClientHtml.addTitleTag(html) 230 html = ClientHtml.addTitleTag(html)
231 html = ClientHtml.addDescriptionTag(html)
232 html = ClientHtml.addServerConfig(html, serverConfig)
217 233
218 ClientHtml.htmlCache[path] = html 234 ClientHtml.htmlCache[path] = html
219 235
@@ -275,6 +291,7 @@ class ClientHtml {
275 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path] 291 if (!isTestInstance() && ClientHtml.htmlCache[path]) return ClientHtml.htmlCache[path]
276 292
277 const buffer = await readFile(path) 293 const buffer = await readFile(path)
294 const serverConfig = await ServerConfigManager.Instance.getHTMLServerConfig()
278 295
279 let html = buffer.toString() 296 let html = buffer.toString()
280 297
@@ -283,6 +300,7 @@ class ClientHtml {
283 html = ClientHtml.addFaviconContentHash(html) 300 html = ClientHtml.addFaviconContentHash(html)
284 html = ClientHtml.addLogoContentHash(html) 301 html = ClientHtml.addLogoContentHash(html)
285 html = ClientHtml.addCustomCSS(html) 302 html = ClientHtml.addCustomCSS(html)
303 html = ClientHtml.addServerConfig(html, serverConfig)
286 html = await ClientHtml.addAsyncPluginCSS(html) 304 html = await ClientHtml.addAsyncPluginCSS(html)
287 305
288 ClientHtml.htmlCache[path] = html 306 ClientHtml.htmlCache[path] = html
@@ -355,6 +373,13 @@ class ClientHtml {
355 return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.CUSTOM_CSS, styleTag) 373 return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.CUSTOM_CSS, styleTag)
356 } 374 }
357 375
376 private static addServerConfig (htmlStringPage: string, serverConfig: HTMLServerConfig) {
377 const serverConfigString = JSON.stringify(serverConfig)
378 const configScriptTag = `<script type="application/javascript">window.PeerTubeServerConfig = '${serverConfigString}'</script>`
379
380 return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.SERVER_CONFIG, configScriptTag)
381 }
382
358 private static async addAsyncPluginCSS (htmlStringPage: string) { 383 private static async addAsyncPluginCSS (htmlStringPage: string) {
359 const globalCSSContent = await readFile(PLUGIN_GLOBAL_CSS_PATH) 384 const globalCSSContent = await readFile(PLUGIN_GLOBAL_CSS_PATH)
360 if (globalCSSContent.byteLength === 0) return htmlStringPage 385 if (globalCSSContent.byteLength === 0) return htmlStringPage