aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/upload.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2021-10-25 17:42:20 +0200
committerGitHub <noreply@github.com>2021-10-25 17:42:20 +0200
commit276250f0a36e00373166d91d539e5220d6f158c7 (patch)
tree394e4fd65912edbbe9266ccfbacfc14f433371e7 /server/controllers/api/videos/upload.ts
parentb2ad0090c182c7f2a8cba1cced3987d408a4b159 (diff)
downloadPeerTube-276250f0a36e00373166d91d539e5220d6f158c7.tar.gz
PeerTube-276250f0a36e00373166d91d539e5220d6f158c7.tar.zst
PeerTube-276250f0a36e00373166d91d539e5220d6f158c7.zip
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>
Diffstat (limited to 'server/controllers/api/videos/upload.ts')
-rw-r--r--server/controllers/api/videos/upload.ts18
1 files changed, 12 insertions, 6 deletions
diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts
index 55cb9cf20..02aadd426 100644
--- a/server/controllers/api/videos/upload.ts
+++ b/server/controllers/api/videos/upload.ts
@@ -7,6 +7,7 @@ import { uuidToShort } from '@server/helpers/uuid'
7import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' 7import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
8import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' 8import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
9import { generateWebTorrentVideoFilename } from '@server/lib/paths' 9import { generateWebTorrentVideoFilename } from '@server/lib/paths'
10import { Redis } from '@server/lib/redis'
10import { 11import {
11 addMoveToObjectStorageJob, 12 addMoveToObjectStorageJob,
12 addOptimizeOrMergeAudioJob, 13 addOptimizeOrMergeAudioJob,
@@ -94,7 +95,7 @@ uploadRouter.delete('/upload-resumable',
94uploadRouter.put('/upload-resumable', 95uploadRouter.put('/upload-resumable',
95 openapiOperationDoc({ operationId: 'uploadResumable' }), 96 openapiOperationDoc({ operationId: 'uploadResumable' }),
96 authenticate, 97 authenticate,
97 uploadxMiddleware, // uploadx doesn't use call next() before the file upload completes 98 uploadxMiddleware, // uploadx doesn't next() before the file upload completes
98 asyncMiddleware(videosAddResumableValidator), 99 asyncMiddleware(videosAddResumableValidator),
99 asyncMiddleware(addVideoResumable) 100 asyncMiddleware(addVideoResumable)
100) 101)
@@ -122,15 +123,20 @@ export async function addVideoLegacy (req: express.Request, res: express.Respons
122 const videoInfo: VideoCreate = req.body 123 const videoInfo: VideoCreate = req.body
123 const files = req.files 124 const files = req.files
124 125
125 return addVideo({ res, videoPhysicalFile, videoInfo, files }) 126 const response = await addVideo({ res, videoPhysicalFile, videoInfo, files })
127
128 return res.json(response)
126} 129}
127 130
128export async function addVideoResumable (_req: express.Request, res: express.Response) { 131export async function addVideoResumable (req: express.Request, res: express.Response) {
129 const videoPhysicalFile = res.locals.videoFileResumable 132 const videoPhysicalFile = res.locals.videoFileResumable
130 const videoInfo = videoPhysicalFile.metadata 133 const videoInfo = videoPhysicalFile.metadata
131 const files = { previewfile: videoInfo.previewfile } 134 const files = { previewfile: videoInfo.previewfile }
132 135
133 return addVideo({ res, videoPhysicalFile, videoInfo, files }) 136 const response = await addVideo({ res, videoPhysicalFile, videoInfo, files })
137 await Redis.Instance.setUploadSession(req.query.upload_id, response)
138
139 return res.json(response)
134} 140}
135 141
136async function addVideo (options: { 142async function addVideo (options: {
@@ -225,13 +231,13 @@ async function addVideo (options: {
225 231
226 Hooks.runAction('action:api.video.uploaded', { video: videoCreated }) 232 Hooks.runAction('action:api.video.uploaded', { video: videoCreated })
227 233
228 return res.json({ 234 return {
229 video: { 235 video: {
230 id: videoCreated.id, 236 id: videoCreated.id,
231 shortUUID: uuidToShort(videoCreated.uuid), 237 shortUUID: uuidToShort(videoCreated.uuid),
232 uuid: videoCreated.uuid 238 uuid: videoCreated.uuid
233 } 239 }
234 }) 240 }
235} 241}
236 242
237async function buildNewFile (videoPhysicalFile: express.VideoUploadFile) { 243async function buildNewFile (videoPhysicalFile: express.VideoUploadFile) {