1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

prevent multiple post-process triggering of upload-resumable (#4175)

* prevent multiple post-process triggering of upload-resumable

* switch from 409 to 503 for upload being processed

* Improve resumable upload check

Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
Rigel Kent 2021-10-25 17:42:20 +02:00 committed by GitHub
parent b2ad0090c1
commit 276250f0a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 107 additions and 13 deletions

View file

@ -7,6 +7,7 @@ import { uuidToShort } from '@server/helpers/uuid'
import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
import { generateWebTorrentVideoFilename } from '@server/lib/paths'
import { Redis } from '@server/lib/redis'
import {
addMoveToObjectStorageJob,
addOptimizeOrMergeAudioJob,
@ -94,7 +95,7 @@ uploadRouter.delete('/upload-resumable',
uploadRouter.put('/upload-resumable',
openapiOperationDoc({ operationId: 'uploadResumable' }),
authenticate,
uploadxMiddleware, // uploadx doesn't use call next() before the file upload completes
uploadxMiddleware, // uploadx doesn't next() before the file upload completes
asyncMiddleware(videosAddResumableValidator),
asyncMiddleware(addVideoResumable)
)
@ -122,15 +123,20 @@ export async function addVideoLegacy (req: express.Request, res: express.Respons
const videoInfo: VideoCreate = req.body
const files = req.files
return addVideo({ res, videoPhysicalFile, videoInfo, files })
const response = await addVideo({ res, videoPhysicalFile, videoInfo, files })
return res.json(response)
}
export async function addVideoResumable (_req: express.Request, res: express.Response) {
export async function addVideoResumable (req: express.Request, res: express.Response) {
const videoPhysicalFile = res.locals.videoFileResumable
const videoInfo = videoPhysicalFile.metadata
const files = { previewfile: videoInfo.previewfile }
return addVideo({ res, videoPhysicalFile, videoInfo, files })
const response = await addVideo({ res, videoPhysicalFile, videoInfo, files })
await Redis.Instance.setUploadSession(req.query.upload_id, response)
return res.json(response)
}
async function addVideo (options: {
@ -225,13 +231,13 @@ async function addVideo (options: {
Hooks.runAction('action:api.video.uploaded', { video: videoCreated })
return res.json({
return {
video: {
id: videoCreated.id,
shortUUID: uuidToShort(videoCreated.uuid),
uuid: videoCreated.uuid
}
})
}
}
async function buildNewFile (videoPhysicalFile: express.VideoUploadFile) {