mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-09-11 13:37:10 +03:00
Fix legacy upload req timeout
This commit is contained in:
parent
05d84f659d
commit
209043e2d4
@ -17,6 +17,7 @@ import {
|
||||
asyncMiddleware,
|
||||
asyncRetryTransactionMiddleware,
|
||||
authenticate,
|
||||
setReqTimeout,
|
||||
videosAddLegacyValidator,
|
||||
videosAddResumableInitValidator,
|
||||
videosAddResumableValidator
|
||||
@ -40,6 +41,7 @@ const reqVideoFileAddResumable = createReqFiles(
|
||||
uploadRouter.post('/upload',
|
||||
openapiOperationDoc({ operationId: 'uploadLegacy' }),
|
||||
authenticate,
|
||||
setReqTimeout(1000 * 60 * 10), // Uploading the video could be long
|
||||
reqVideoFileAdd,
|
||||
asyncMiddleware(videosAddLegacyValidator),
|
||||
asyncRetryTransactionMiddleware(addVideoLegacy)
|
||||
@ -74,17 +76,7 @@ export {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function addVideoLegacy (req: express.Request, res: express.Response) {
|
||||
// Uploading the video could be long
|
||||
// Set timeout to 10 minutes, as Express's default is 2 minutes
|
||||
req.setTimeout(1000 * 60 * 10, () => {
|
||||
logger.error('Video upload has timed out.')
|
||||
return res.fail({
|
||||
status: HttpStatusCode.REQUEST_TIMEOUT_408,
|
||||
message: 'Video upload has timed out.'
|
||||
})
|
||||
})
|
||||
|
||||
const videoPhysicalFile = req.files['videofile'][0]
|
||||
const videoPhysicalFile = req.files['videofile'][0]
|
||||
const videoInfo: VideoCreate = req.body
|
||||
const files = req.files
|
||||
|
||||
|
18
server/core/middlewares/express.ts
Normal file
18
server/core/middlewares/express.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { HttpStatusCode } from '@peertube/peertube-models'
|
||||
import { logger } from '@server/helpers/logger.js'
|
||||
import express from 'express'
|
||||
|
||||
export function setReqTimeout (timeoutMs: number) {
|
||||
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
req.setTimeout(timeoutMs, () => {
|
||||
logger.error('Express request timeout in ' + req.originalUrl)
|
||||
|
||||
return res.fail({
|
||||
status: HttpStatusCode.REQUEST_TIMEOUT_408,
|
||||
message: 'Request has timed out.'
|
||||
})
|
||||
})
|
||||
|
||||
next()
|
||||
}
|
||||
}
|
@ -10,5 +10,6 @@ export * from './sort.js'
|
||||
export * from './user-right.js'
|
||||
export * from './dnt.js'
|
||||
export * from './error.js'
|
||||
export * from './express.js'
|
||||
export * from './doc.js'
|
||||
export * from './csp.js'
|
||||
|
Loading…
Reference in New Issue
Block a user