1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

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
This commit is contained in:
Rigel Kent 2020-12-08 21:16:10 +01:00 committed by GitHub
parent c977fd3ec9
commit f2eb23cd87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 506 additions and 310 deletions

View file

@ -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 { 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 { asyncMiddleware, embedCSP } from '../middlewares'
import { HttpStatusCode } from '@shared/core-utils'
import { root } from '../helpers/core-utils'
import { STATIC_MAX_AGE } from '../initializers/constants'
import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/client-html'
import { asyncMiddleware, embedCSP } from '../middlewares'
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')