aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/client.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-08 21:16:10 +0100
committerGitHub <noreply@github.com>2020-12-08 21:16:10 +0100
commitf2eb23cd87cf32b8fe545178143b5f49e06a58da (patch)
treeaf7d59945af70e28fd85047e2c688c59a908f548 /server/controllers/client.ts
parentc977fd3ec931c059111ddb2b8d6ddbb20b6b99a1 (diff)
downloadPeerTube-f2eb23cd87cf32b8fe545178143b5f49e06a58da.tar.gz
PeerTube-f2eb23cd87cf32b8fe545178143b5f49e06a58da.tar.zst
PeerTube-f2eb23cd87cf32b8fe545178143b5f49e06a58da.zip
emit more specific status codes on video upload (#3423)
- reduce http status codes list to potentially useful codes - convert more codes to typed ones - factorize html generator for error responses
Diffstat (limited to 'server/controllers/client.ts')
-rw-r--r--server/controllers/client.ts32
1 files changed, 3 insertions, 29 deletions
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'
3import { join } from 'path' 3import { join } from 'path'
4import { CONFIG } from '@server/initializers/config' 4import { CONFIG } from '@server/initializers/config'
5import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n' 5import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
6import { HttpStatusCode } from '@shared/core-utils'
6import { root } from '../helpers/core-utils' 7import { root } from '../helpers/core-utils'
7import { logger } from '../helpers/logger' 8import { STATIC_MAX_AGE } from '../initializers/constants'
8import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants' 9import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html'
9import { ClientHtml } from '../lib/client-html'
10import { asyncMiddleware, embedCSP } from '../middlewares' 10import { asyncMiddleware, embedCSP } from '../middlewares'
11import { HttpStatusCode } from '@shared/core-utils'
12 11
13const clientsRouter = express.Router() 12const clientsRouter = express.Router()
14 13
@@ -118,31 +117,12 @@ function serveServerTranslations (req: express.Request, res: express.Response) {
118 return res.sendStatus(HttpStatusCode.NOT_FOUND_404) 117 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
119} 118}
120 119
121async function serveIndexHTML (req: express.Request, res: express.Response) {
122 if (req.accepts(ACCEPT_HEADERS) === 'html') {
123 try {
124 await generateHTMLPage(req, res, req.params.language)
125 return
126 } catch (err) {
127 logger.error('Cannot generate HTML page.', err)
128 }
129 }
130
131 return res.status(HttpStatusCode.INTERNAL_SERVER_ERROR_500).end()
132}
133
134async function generateEmbedHtmlPage (req: express.Request, res: express.Response) { 120async function generateEmbedHtmlPage (req: express.Request, res: express.Response) {
135 const html = await ClientHtml.getEmbedHTML() 121 const html = await ClientHtml.getEmbedHTML()
136 122
137 return sendHTML(html, res) 123 return sendHTML(html, res)
138} 124}
139 125
140async function generateHTMLPage (req: express.Request, res: express.Response, paramLang?: string) {
141 const html = await ClientHtml.getDefaultHTMLPage(req, res, paramLang)
142
143 return sendHTML(html, res)
144}
145
146async function generateWatchHtmlPage (req: express.Request, res: express.Response) { 126async function generateWatchHtmlPage (req: express.Request, res: express.Response) {
147 const html = await ClientHtml.getWatchHTMLPage(req.params.id + '', req, res) 127 const html = await ClientHtml.getWatchHTMLPage(req.params.id + '', req, res)
148 128
@@ -167,12 +147,6 @@ async function generateVideoChannelHtmlPage (req: express.Request, res: express.
167 return sendHTML(html, res) 147 return sendHTML(html, res)
168} 148}
169 149
170function sendHTML (html: string, res: express.Response) {
171 res.set('Content-Type', 'text/html; charset=UTF-8')
172
173 return res.send(html)
174}
175
176async function generateManifest (req: express.Request, res: express.Response) { 150async function generateManifest (req: express.Request, res: express.Response) {
177 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest') 151 const manifestPhysicalPath = join(root(), 'client', 'dist', 'manifest.webmanifest')
178 const manifestJson = await fs.readFile(manifestPhysicalPath, 'utf8') 152 const manifestJson = await fs.readFile(manifestPhysicalPath, 'utf8')