diff options
Diffstat (limited to 'server/lib/client-html.ts')
-rw-r--r-- | server/lib/client-html.ts | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index d97d23180..32f5d29ab 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as Bluebird from 'bluebird' | ||
2 | import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' | 3 | import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' |
3 | import { | 4 | import { |
4 | AVATARS_SIZE, | 5 | AVATARS_SIZE, |
@@ -6,7 +7,8 @@ import { | |||
6 | EMBED_SIZE, | 7 | EMBED_SIZE, |
7 | PLUGIN_GLOBAL_CSS_PATH, | 8 | PLUGIN_GLOBAL_CSS_PATH, |
8 | WEBSERVER, | 9 | WEBSERVER, |
9 | FILES_CONTENT_HASH | 10 | FILES_CONTENT_HASH, |
11 | ACCEPT_HEADERS | ||
10 | } from '../initializers/constants' | 12 | } from '../initializers/constants' |
11 | import { join } from 'path' | 13 | import { join } from 'path' |
12 | import { escapeHTML, isTestInstance, sha256 } from '../helpers/core-utils' | 14 | import { escapeHTML, isTestInstance, sha256 } from '../helpers/core-utils' |
@@ -18,7 +20,6 @@ import { readFile } from 'fs-extra' | |||
18 | import { getActivityStreamDuration } from '../models/video/video-format-utils' | 20 | import { getActivityStreamDuration } from '../models/video/video-format-utils' |
19 | import { AccountModel } from '../models/account/account' | 21 | import { AccountModel } from '../models/account/account' |
20 | import { VideoChannelModel } from '../models/video/video-channel' | 22 | import { VideoChannelModel } from '../models/video/video-channel' |
21 | import * as Bluebird from 'bluebird' | ||
22 | import { CONFIG } from '../initializers/config' | 23 | import { CONFIG } from '../initializers/config' |
23 | import { logger } from '../helpers/logger' | 24 | import { logger } from '../helpers/logger' |
24 | import { MAccountActor, MChannelActor } from '../types/models' | 25 | import { MAccountActor, MChannelActor } from '../types/models' |
@@ -53,7 +54,7 @@ type Tags = { | |||
53 | } | 54 | } |
54 | } | 55 | } |
55 | 56 | ||
56 | export class ClientHtml { | 57 | class ClientHtml { |
57 | 58 | ||
58 | private static htmlCache: { [path: string]: string } = {} | 59 | private static htmlCache: { [path: string]: string } = {} |
59 | 60 | ||
@@ -505,3 +506,38 @@ export class ClientHtml { | |||
505 | return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.META_TAGS, tagsString) | 506 | return htmlStringPage.replace(CUSTOM_HTML_TAG_COMMENTS.META_TAGS, tagsString) |
506 | } | 507 | } |
507 | } | 508 | } |
509 | |||
510 | function sendHTML (html: string, res: express.Response) { | ||
511 | res.set('Content-Type', 'text/html; charset=UTF-8') | ||
512 | |||
513 | return res.send(html) | ||
514 | } | ||
515 | |||
516 | async function serveIndexHTML (req: express.Request, res: express.Response) { | ||
517 | if (req.accepts(ACCEPT_HEADERS) === 'html' || | ||
518 | !req.headers.accept) { | ||
519 | try { | ||
520 | await generateHTMLPage(req, res, req.params.language) | ||
521 | return | ||
522 | } catch (err) { | ||
523 | logger.error('Cannot generate HTML page.', err) | ||
524 | return res.sendStatus(HttpStatusCode.INTERNAL_SERVER_ERROR_500) | ||
525 | } | ||
526 | } | ||
527 | |||
528 | return res.sendStatus(HttpStatusCode.NOT_ACCEPTABLE_406) | ||
529 | } | ||
530 | |||
531 | // --------------------------------------------------------------------------- | ||
532 | |||
533 | export { | ||
534 | ClientHtml, | ||
535 | sendHTML, | ||
536 | serveIndexHTML | ||
537 | } | ||
538 | |||
539 | async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) { | ||
540 | const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang) | ||
541 | |||
542 | return sendHTML(html, res) | ||
543 | } | ||