X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fclient.ts;h=bd1f19f8c913ab30a83a69c4d51be06311cd0459;hb=f2eb23cd87cf32b8fe545178143b5f49e06a58da;hp=49e6fd66132e96d123587a526ca2cda251e3c219;hpb=c977fd3ec931c059111ddb2b8d6ddbb20b6b99a1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 49e6fd661..bd1f19f8c 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts @@ -3,12 +3,11 @@ import { constants, promises as fs } from 'fs' import { join } from 'path' import { CONFIG } from '@server/initializers/config' import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' +import { HttpStatusCode } from '@shared/core-utils' import { root } from '../helpers/core-utils' -import { logger } from '../helpers/logger' -import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants' -import { ClientHtml } from '../lib/client-html' +import { STATIC_MAX_AGE } from '../initializers/constants' +import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html' import { asyncMiddleware, embedCSP } from '../middlewares' -import { HttpStatusCode } from '@shared/core-utils' const clientsRouter = express.Router() @@ -118,31 +117,12 @@ function serveServerTranslations (req: express.Request, res: express.Response) { return res.sendStatus(HttpStatusCode.NOT_FOUND_404) } -async function serveIndexHTML (req: express.Request, res: express.Response) { - if (req.accepts(ACCEPT_HEADERS) === 'html') { - try { - await generateHTMLPage(req, res, req.params.language) - return - } catch (err) { - logger.error('Cannot generate HTML page.', err) - } - } - - return res.status(HttpStatusCode.INTERNAL_SERVER_ERROR_500).end() -} - async function generateEmbedHtmlPage (req: express.Request, res: express.Response) { const html = await ClientHtml.getEmbedHTML() return sendHTML(html, res) } -async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) { - const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang) - - return sendHTML(html, res) -} - async function generateWatchHtmlPage (req: express.Request, res: express.Response) { const html = await ClientHtml.getWatchHTMLPage(req.params.id + '', req, res) @@ -167,12 +147,6 @@ async function generateVideoChannelHtmlPage (req: express.Request, res: express. return sendHTML(html, res) } -function sendHTML (html: string, res: express.Response) { - res.set('Content-Type', 'text/html; charset=UTF-8') - - return res.send(html) -} - async function generateManifest (req: express.Request, res: express.Response) { const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest') const manifestJson = await fs.readFile(manifestPhysicalPath, 'utf8')