Fix legacy upload req timeout

pull/6454/head
Chocobozzz 2024-06-24 09:10:11 +02:00
parent 05d84f659d
commit 209043e2d4
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 22 additions and 11 deletions

View File

@ -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

View 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()
}
}

View File

@ -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'