diff options
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 23ee9778a..e486887a7 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -1,6 +1,8 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { body, header, param, query, ValidationChain } from 'express-validator' | 2 | import { body, header, param, query, ValidationChain } from 'express-validator' |
3 | import { isTestInstance } from '@server/helpers/core-utils' | ||
3 | import { getResumableUploadPath } from '@server/helpers/upload' | 4 | import { getResumableUploadPath } from '@server/helpers/upload' |
5 | import { Redis } from '@server/lib/redis' | ||
4 | import { isAbleToUploadVideo } from '@server/lib/user' | 6 | import { isAbleToUploadVideo } from '@server/lib/user' |
5 | import { getServerActor } from '@server/models/application/application' | 7 | import { getServerActor } from '@server/models/application/application' |
6 | import { ExpressPromiseHandler } from '@server/types/express' | 8 | import { ExpressPromiseHandler } from '@server/types/express' |
@@ -105,12 +107,34 @@ const videosAddLegacyValidator = getCommonVideoEditAttributes().concat([ | |||
105 | const videosAddResumableValidator = [ | 107 | const videosAddResumableValidator = [ |
106 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 108 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
107 | const user = res.locals.oauth.token.User | 109 | const user = res.locals.oauth.token.User |
108 | |||
109 | const body: express.CustomUploadXFile<express.UploadXFileMetadata> = req.body | 110 | const body: express.CustomUploadXFile<express.UploadXFileMetadata> = req.body |
110 | const file = { ...body, duration: undefined, path: getResumableUploadPath(body.id), filename: body.metadata.filename } | 111 | const file = { ...body, duration: undefined, path: getResumableUploadPath(body.id), filename: body.metadata.filename } |
111 | |||
112 | const cleanup = () => deleteFileAndCatch(file.path) | 112 | const cleanup = () => deleteFileAndCatch(file.path) |
113 | 113 | ||
114 | const uploadId = req.query.upload_id | ||
115 | const sessionExists = await Redis.Instance.doesUploadSessionExist(uploadId) | ||
116 | |||
117 | if (sessionExists) { | ||
118 | const sessionResponse = await Redis.Instance.getUploadSession(uploadId) | ||
119 | |||
120 | if (!sessionResponse) { | ||
121 | res.setHeader('Retry-After', 300) // ask to retry after 5 min, knowing the upload_id is kept for up to 15 min after completion | ||
122 | |||
123 | return res.fail({ | ||
124 | status: HttpStatusCode.SERVICE_UNAVAILABLE_503, | ||
125 | message: 'The upload is already being processed' | ||
126 | }) | ||
127 | } | ||
128 | |||
129 | if (isTestInstance()) { | ||
130 | res.setHeader('x-resumable-upload-cached', 'true') | ||
131 | } | ||
132 | |||
133 | return res.json(sessionResponse) | ||
134 | } | ||
135 | |||
136 | await Redis.Instance.setUploadSession(uploadId) | ||
137 | |||
114 | if (!await doesVideoChannelOfAccountExist(file.metadata.channelId, user, res)) return cleanup() | 138 | if (!await doesVideoChannelOfAccountExist(file.metadata.channelId, user, res)) return cleanup() |
115 | 139 | ||
116 | try { | 140 | try { |