]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/client.ts
Don't expose constants directly in initializers/
[github/Chocobozzz/PeerTube.git] / server / controllers / client.ts
index c33061289c947487a33a5e23e91ed1bf9cfce74f..f51470b419507b64abde1c51b10346e8fc678c5f 100644 (file)
@@ -1,8 +1,8 @@
 import * as express from 'express'
 import { join } from 'path'
 import { root } from '../helpers/core-utils'
-import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers'
-import { asyncMiddleware } from '../middlewares'
+import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants'
+import { asyncMiddleware, embedCSP } from '../middlewares'
 import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n'
 import { ClientHtml } from '../lib/client-html'
 import { logger } from '../helpers/logger'
@@ -16,26 +16,27 @@ const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
 
 // Special route that add OpenGraph and oEmbed tags
 // Do not use a template engine for a so little thing
-clientsRouter.use('/videos/watch/:id',
-  asyncMiddleware(generateWatchHtmlPage)
-)
+clientsRouter.use('/videos/watch/:id', asyncMiddleware(generateWatchHtmlPage))
+clientsRouter.use('/accounts/:nameWithHost', asyncMiddleware(generateAccountHtmlPage))
+clientsRouter.use('/video-channels/:nameWithHost', asyncMiddleware(generateVideoChannelHtmlPage))
 
-clientsRouter.use('' +
+clientsRouter.use(
   '/videos/embed',
-  (req: express.Request, res: express.Response, next: express.NextFunction) => {
+  embedCSP,
+  (req: express.Request, res: express.Response) => {
     res.removeHeader('X-Frame-Options')
     res.sendFile(embedPath)
   }
 )
-clientsRouter.use('' +
-  '/videos/test-embed', (req: express.Request, res: express.Response, next: express.NextFunction) => {
-  res.sendFile(testEmbedPath)
-})
+clientsRouter.use(
+  '/videos/test-embed',
+  (req: express.Request, res: express.Response) => res.sendFile(testEmbedPath)
+)
 
 // Static HTML/CSS/JS client files
 
 const staticClientFiles = [
-  'manifest.json',
+  'manifest.webmanifest',
   'ngsw-worker.js',
   'ngsw.json'
 ]
@@ -89,7 +90,7 @@ export {
 // ---------------------------------------------------------------------------
 
 async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) {
-  const html = await ClientHtml.getIndexHTML(req, res, paramLang)
+  const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang)
 
   return sendHTML(html, res)
 }
@@ -100,6 +101,18 @@ async function generateWatchHtmlPage (req: express.Request, res: express.Respons
   return sendHTML(html, res)
 }
 
+async function generateAccountHtmlPage (req: express.Request, res: express.Response) {
+  const html = await ClientHtml.getAccountHTMLPage(req.params.nameWithHost, req, res)
+
+  return sendHTML(html, res)
+}
+
+async function generateVideoChannelHtmlPage (req: express.Request, res: express.Response) {
+  const html = await ClientHtml.getVideoChannelHTMLPage(req.params.nameWithHost, req, res)
+
+  return sendHTML(html, res)
+}
+
 function sendHTML (html: string, res: express.Response) {
   res.set('Content-Type', 'text/html; charset=UTF-8')