diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2021-10-25 17:42:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-25 17:42:20 +0200 |
commit | 276250f0a36e00373166d91d539e5220d6f158c7 (patch) | |
tree | 394e4fd65912edbbe9266ccfbacfc14f433371e7 /server/lib/redis.ts | |
parent | b2ad0090c182c7f2a8cba1cced3987d408a4b159 (diff) | |
download | PeerTube-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/lib/redis.ts')
-rw-r--r-- | server/lib/redis.ts | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/server/lib/redis.ts b/server/lib/redis.ts index d1d88d853..46617b07e 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts | |||
@@ -9,7 +9,8 @@ import { | |||
9 | USER_PASSWORD_CREATE_LIFETIME, | 9 | USER_PASSWORD_CREATE_LIFETIME, |
10 | VIEW_LIFETIME, | 10 | VIEW_LIFETIME, |
11 | WEBSERVER, | 11 | WEBSERVER, |
12 | TRACKER_RATE_LIMITS | 12 | TRACKER_RATE_LIMITS, |
13 | RESUMABLE_UPLOAD_SESSION_LIFETIME | ||
13 | } from '../initializers/constants' | 14 | } from '../initializers/constants' |
14 | import { CONFIG } from '../initializers/config' | 15 | import { CONFIG } from '../initializers/config' |
15 | 16 | ||
@@ -202,6 +203,30 @@ class Redis { | |||
202 | ]) | 203 | ]) |
203 | } | 204 | } |
204 | 205 | ||
206 | /* ************ Resumable uploads final responses ************ */ | ||
207 | |||
208 | setUploadSession (uploadId: string, response?: { video: { id: number, shortUUID: string, uuid: string } }) { | ||
209 | return this.setValue( | ||
210 | 'resumable-upload-' + uploadId, | ||
211 | response | ||
212 | ? JSON.stringify(response) | ||
213 | : '', | ||
214 | RESUMABLE_UPLOAD_SESSION_LIFETIME | ||
215 | ) | ||
216 | } | ||
217 | |||
218 | doesUploadSessionExist (uploadId: string) { | ||
219 | return this.exists('resumable-upload-' + uploadId) | ||
220 | } | ||
221 | |||
222 | async getUploadSession (uploadId: string) { | ||
223 | const value = await this.getValue('resumable-upload-' + uploadId) | ||
224 | |||
225 | return value | ||
226 | ? JSON.parse(value) | ||
227 | : '' | ||
228 | } | ||
229 | |||
205 | /* ************ Keys generation ************ */ | 230 | /* ************ Keys generation ************ */ |
206 | 231 | ||
207 | generateCachedRouteKey (req: express.Request) { | 232 | generateCachedRouteKey (req: express.Request) { |