mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Add global rate limit to video download
This commit is contained in:
parent
49a6211f25
commit
25c5507a03
10 changed files with 354 additions and 235 deletions
|
@ -12,7 +12,7 @@ import {
|
|||
} from '@server/lib/object-storage/index.js'
|
||||
import { getFSUserExportFilePath } from '@server/lib/paths.js'
|
||||
import { Hooks } from '@server/lib/plugins/hooks.js'
|
||||
import { muxToMergeVideoFiles } from '@server/lib/video-file.js'
|
||||
import { VideoDownload } from '@server/lib/video-download.js'
|
||||
import { VideoPathManager } from '@server/lib/video-path-manager.js'
|
||||
import {
|
||||
MStreamingPlaylist,
|
||||
|
@ -27,7 +27,9 @@ import cors from 'cors'
|
|||
import express from 'express'
|
||||
import { DOWNLOAD_PATHS, WEBSERVER } from '../initializers/constants.js'
|
||||
import {
|
||||
asyncMiddleware, buildRateLimiter, optionalAuthenticate,
|
||||
asyncMiddleware,
|
||||
buildRateLimiter,
|
||||
optionalAuthenticate,
|
||||
originalVideoFileDownloadValidator,
|
||||
userExportDownloadValidator,
|
||||
videosDownloadValidator,
|
||||
|
@ -244,6 +246,13 @@ async function downloadGeneratedVideoFile (req: express.Request, res: express.Re
|
|||
|
||||
if (!checkAllowResult(res, allowParameters, allowedResult)) return
|
||||
|
||||
if (VideoDownload.totalDownloads > CONFIG.DOWNLOAD_GENERATE_VIDEO.MAX_PARALLEL_DOWNLOADS) {
|
||||
return res.fail({
|
||||
status: HttpStatusCode.TOO_MANY_REQUESTS_429,
|
||||
message: `Too many parallel downloads on this server. Please try again later.`
|
||||
})
|
||||
}
|
||||
|
||||
const maxResolutionFile = maxBy(videoFiles, 'resolution')
|
||||
|
||||
// Prefer m4a extension for the user if this is a mp4 audio file only
|
||||
|
@ -260,7 +269,7 @@ async function downloadGeneratedVideoFile (req: express.Request, res: express.Re
|
|||
|
||||
res.type(extname)
|
||||
|
||||
await muxToMergeVideoFiles({ video, videoFiles, output: res })
|
||||
await new VideoDownload({ video, videoFiles }).muxToMergeVideoFiles(res)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue