mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +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:
parent
c977fd3ec9
commit
f2eb23cd87
53 changed files with 506 additions and 310 deletions
|
@ -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')
|
||||
|
|
|
@ -27,6 +27,7 @@ import { getTorrentFilePath, getVideoFilePath } from '@server/lib/video-paths'
|
|||
import { getThemeOrDefault } from '../lib/plugins/theme-utils'
|
||||
import { getEnabledResolutions, getRegisteredPlugins, getRegisteredThemes } from '@server/controllers/api/config'
|
||||
import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
|
||||
import { serveIndexHTML } from '@server/lib/client-html'
|
||||
|
||||
const staticRouter = express.Router()
|
||||
|
||||
|
@ -119,6 +120,11 @@ staticRouter.get('/robots.txt',
|
|||
}
|
||||
)
|
||||
|
||||
staticRouter.all('/teapot',
|
||||
getCup,
|
||||
asyncMiddleware(serveIndexHTML)
|
||||
)
|
||||
|
||||
// security.txt service
|
||||
staticRouter.get('/security.txt',
|
||||
(_, res: express.Response) => {
|
||||
|
@ -391,3 +397,11 @@ function getHLSPlaylist (video: MVideoFullLight) {
|
|||
|
||||
return Object.assign(playlist, { Video: video })
|
||||
}
|
||||
|
||||
function getCup (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
res.status(HttpStatusCode.I_AM_A_TEAPOT_418)
|
||||
res.setHeader('Accept-Additions', 'Non-Dairy;1,Sugar;1')
|
||||
res.setHeader('Safe', 'if-sepia-awake')
|
||||
|
||||
return next()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue