From 276250f0a36e00373166d91d539e5220d6f158c7 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 25 Oct 2021 17:42:20 +0200 Subject: 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 --- server/lib/job-queue/job-queue.ts | 2 ++ server/lib/redis.ts | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'server/lib') 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 { ActivitypubHttpFetcherPayload, ActivitypubHttpUnicastPayload, ActorKeysPayload, + DeleteResumableUploadMetaFilePayload, EmailPayload, JobState, JobType, @@ -52,6 +53,7 @@ type CreateJobArgument = { type: 'video-live-ending', payload: VideoLiveEndingPayload } | { type: 'actor-keys', payload: ActorKeysPayload } | { type: 'video-redundancy', payload: VideoRedundancyPayload } | + { type: 'delete-resumable-upload-meta-file', payload: DeleteResumableUploadMetaFilePayload } | { type: 'move-to-object-storage', payload: MoveObjectStoragePayload } 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 { USER_PASSWORD_CREATE_LIFETIME, VIEW_LIFETIME, WEBSERVER, - TRACKER_RATE_LIMITS + TRACKER_RATE_LIMITS, + RESUMABLE_UPLOAD_SESSION_LIFETIME } from '../initializers/constants' import { CONFIG } from '../initializers/config' @@ -202,6 +203,30 @@ class Redis { ]) } + /* ************ Resumable uploads final responses ************ */ + + setUploadSession (uploadId: string, response?: { video: { id: number, shortUUID: string, uuid: string } }) { + return this.setValue( + 'resumable-upload-' + uploadId, + response + ? JSON.stringify(response) + : '', + RESUMABLE_UPLOAD_SESSION_LIFETIME + ) + } + + doesUploadSessionExist (uploadId: string) { + return this.exists('resumable-upload-' + uploadId) + } + + async getUploadSession (uploadId: string) { + const value = await this.getValue('resumable-upload-' + uploadId) + + return value + ? JSON.parse(value) + : '' + } + /* ************ Keys generation ************ */ generateCachedRouteKey (req: express.Request) { -- cgit v1.2.3