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 | |
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')
-rw-r--r-- | server/lib/job-queue/job-queue.ts | 2 | ||||
-rw-r--r-- | server/lib/redis.ts | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts index 4cda12b57..53d6b6a9c 100644 --- a/server/lib/job-queue/job-queue.ts +++ b/server/lib/job-queue/job-queue.ts | |||
@@ -8,6 +8,7 @@ import { | |||
8 | ActivitypubHttpFetcherPayload, | 8 | ActivitypubHttpFetcherPayload, |
9 | ActivitypubHttpUnicastPayload, | 9 | ActivitypubHttpUnicastPayload, |
10 | ActorKeysPayload, | 10 | ActorKeysPayload, |
11 | DeleteResumableUploadMetaFilePayload, | ||
11 | EmailPayload, | 12 | EmailPayload, |
12 | JobState, | 13 | JobState, |
13 | JobType, | 14 | JobType, |
@@ -52,6 +53,7 @@ type CreateJobArgument = | |||
52 | { type: 'video-live-ending', payload: VideoLiveEndingPayload } | | 53 | { type: 'video-live-ending', payload: VideoLiveEndingPayload } | |
53 | { type: 'actor-keys', payload: ActorKeysPayload } | | 54 | { type: 'actor-keys', payload: ActorKeysPayload } | |
54 | { type: 'video-redundancy', payload: VideoRedundancyPayload } | | 55 | { type: 'video-redundancy', payload: VideoRedundancyPayload } | |
56 | { type: 'delete-resumable-upload-meta-file', payload: DeleteResumableUploadMetaFilePayload } | | ||
55 | { type: 'move-to-object-storage', payload: MoveObjectStoragePayload } | 57 | { type: 'move-to-object-storage', payload: MoveObjectStoragePayload } |
56 | 58 | ||
57 | export type CreateJobOptions = { | 59 | export type CreateJobOptions = { |
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) { |