From 25e0cc092003b2b1e54f0b39956477a2d2c86181 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Fri, 20 Dec 2024 14:10:55 +0100 Subject: [PATCH 1/3] fix: make deferred upload length optional --- packages/@uppy/companion/KUBERNETES.md | 1 + packages/@uppy/companion/env_example | 1 + packages/@uppy/companion/src/server/Uploader.js | 9 +++++++-- packages/@uppy/companion/src/standalone/helper.js | 1 + packages/@uppy/companion/test/mockserver.js | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/@uppy/companion/KUBERNETES.md b/packages/@uppy/companion/KUBERNETES.md index b9c908bb3a..2af0df9078 100644 --- a/packages/@uppy/companion/KUBERNETES.md +++ b/packages/@uppy/companion/KUBERNETES.md @@ -28,6 +28,7 @@ data: COMPANION_DOMAINS: 'sub1.domain.com,sub2.domain.com,sub3.domain.com' COMPANION_PROTOCOL: 'YOUR SERVER PROTOCOL' COMPANION_STREAMING_UPLOAD: true + COMPANION_DEFERRED_UPLOAD_LENGTH: true COMPANION_REDIS_URL: redis://:superSecretPassword@uppy-redis.uppy.svc.cluster.local:6379 COMPANION_SECRET: 'shh!Issa Secret!' COMPANION_PREAUTH_SECRET: 'another secret' diff --git a/packages/@uppy/companion/env_example b/packages/@uppy/companion/env_example index 08b3e0acf1..768b2f6d78 100644 --- a/packages/@uppy/companion/env_example +++ b/packages/@uppy/companion/env_example @@ -5,6 +5,7 @@ COMPANION_SELF_ENDPOINT=uppy.xxxx.com COMPANION_HIDE_METRICS=false COMPANION_HIDE_WELCOME=false COMPANION_STREAMING_UPLOAD=true +COMPANION_DEFERRED_UPLOAD_LENGTH=true COMPANION_PROTOCOL=https COMPANION_DATADIR=/mnt/uppy-server-data diff --git a/packages/@uppy/companion/src/server/Uploader.js b/packages/@uppy/companion/src/server/Uploader.js index 9c2e3dd64b..7291ae2d29 100644 --- a/packages/@uppy/companion/src/server/Uploader.js +++ b/packages/@uppy/companion/src/server/Uploader.js @@ -509,9 +509,7 @@ class Uploader { const tusOptions = { endpoint: this.options.endpoint, uploadUrl: this.options.uploadUrl, - uploadLengthDeferred: !isFileStream, retryDelays: [0, 1000, 3000, 5000], - uploadSize: isFileStream ? this.size : undefined, chunkSize, headers: headerSanitize(this.options.headers), addRequestId: true, @@ -553,6 +551,13 @@ class Uploader { }, } + if (this.options.companionOptions.deferredUploadLength && !isFileStream) { + tusOptions.uploadLengthDeferred = true + } else { + tusOptions.uploadLengthDeferred = false + tusOptions.uploadSize = this.size + } + this.tus = new tus.Upload(stream, tusOptions) this.tus.start() diff --git a/packages/@uppy/companion/src/standalone/helper.js b/packages/@uppy/companion/src/standalone/helper.js index 57494dadb8..9a772e0192 100644 --- a/packages/@uppy/companion/src/standalone/helper.js +++ b/packages/@uppy/companion/src/standalone/helper.js @@ -183,6 +183,7 @@ const getConfigFromEnv = () => { // cookieDomain is kind of a hack to support distributed systems. This should be improved but we never got so far. cookieDomain: process.env.COMPANION_COOKIE_DOMAIN, streamingUpload: process.env.COMPANION_STREAMING_UPLOAD ? process.env.COMPANION_STREAMING_UPLOAD === 'true' : undefined, + deferredUploadLength: process.env.COMPANION_DEFERRED_UPLOAD_LENGTH ? process.env.COMPANION_DEFERRED_UPLOAD_LENGTH === 'true' : true, maxFileSize: process.env.COMPANION_MAX_FILE_SIZE ? parseInt(process.env.COMPANION_MAX_FILE_SIZE, 10) : undefined, chunkSize: process.env.COMPANION_CHUNK_SIZE ? parseInt(process.env.COMPANION_CHUNK_SIZE, 10) : undefined, clientSocketConnectTimeout: process.env.COMPANION_CLIENT_SOCKET_CONNECT_TIMEOUT diff --git a/packages/@uppy/companion/test/mockserver.js b/packages/@uppy/companion/test/mockserver.js index 9ee1779e96..c18d0f2098 100644 --- a/packages/@uppy/companion/test/mockserver.js +++ b/packages/@uppy/companion/test/mockserver.js @@ -12,6 +12,7 @@ const defaultEnv = { COMPANION_HIDE_WELCOME: 'false', COMPANION_STREAMING_UPLOAD: 'true', + COMPANION_DEFERRED_UPLOAD_LENGTH: 'true', COMPANION_ALLOW_LOCAL_URLS: 'false', COMPANION_PROTOCOL: 'http', From 26471e1f47fe9db09dbd41acf16d5c90b1b0f500 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Tue, 7 Jan 2025 14:43:19 +0100 Subject: [PATCH 2/3] refactor: rename COMPANION_DEFERRED_UPLOAD_LENGTH to COMPANION_TUS_DEFERRED_UPLOAD_LENGTH --- packages/@uppy/companion/KUBERNETES.md | 2 +- packages/@uppy/companion/env_example | 2 +- packages/@uppy/companion/src/server/Uploader.js | 2 +- packages/@uppy/companion/src/standalone/helper.js | 2 +- packages/@uppy/companion/test/mockserver.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/@uppy/companion/KUBERNETES.md b/packages/@uppy/companion/KUBERNETES.md index 2af0df9078..5b148a4780 100644 --- a/packages/@uppy/companion/KUBERNETES.md +++ b/packages/@uppy/companion/KUBERNETES.md @@ -28,7 +28,7 @@ data: COMPANION_DOMAINS: 'sub1.domain.com,sub2.domain.com,sub3.domain.com' COMPANION_PROTOCOL: 'YOUR SERVER PROTOCOL' COMPANION_STREAMING_UPLOAD: true - COMPANION_DEFERRED_UPLOAD_LENGTH: true + COMPANION_TUS_DEFERRED_UPLOAD_LENGTH: true COMPANION_REDIS_URL: redis://:superSecretPassword@uppy-redis.uppy.svc.cluster.local:6379 COMPANION_SECRET: 'shh!Issa Secret!' COMPANION_PREAUTH_SECRET: 'another secret' diff --git a/packages/@uppy/companion/env_example b/packages/@uppy/companion/env_example index 768b2f6d78..b166facda9 100644 --- a/packages/@uppy/companion/env_example +++ b/packages/@uppy/companion/env_example @@ -5,7 +5,7 @@ COMPANION_SELF_ENDPOINT=uppy.xxxx.com COMPANION_HIDE_METRICS=false COMPANION_HIDE_WELCOME=false COMPANION_STREAMING_UPLOAD=true -COMPANION_DEFERRED_UPLOAD_LENGTH=true +COMPANION_TUS_DEFERRED_UPLOAD_LENGTH=true COMPANION_PROTOCOL=https COMPANION_DATADIR=/mnt/uppy-server-data diff --git a/packages/@uppy/companion/src/server/Uploader.js b/packages/@uppy/companion/src/server/Uploader.js index 7291ae2d29..3ba15f60dd 100644 --- a/packages/@uppy/companion/src/server/Uploader.js +++ b/packages/@uppy/companion/src/server/Uploader.js @@ -551,7 +551,7 @@ class Uploader { }, } - if (this.options.companionOptions.deferredUploadLength && !isFileStream) { + if (this.options.companionOptions.tusDeferredUploadLength && !isFileStream) { tusOptions.uploadLengthDeferred = true } else { tusOptions.uploadLengthDeferred = false diff --git a/packages/@uppy/companion/src/standalone/helper.js b/packages/@uppy/companion/src/standalone/helper.js index 9a772e0192..4db99e03e7 100644 --- a/packages/@uppy/companion/src/standalone/helper.js +++ b/packages/@uppy/companion/src/standalone/helper.js @@ -183,7 +183,7 @@ const getConfigFromEnv = () => { // cookieDomain is kind of a hack to support distributed systems. This should be improved but we never got so far. cookieDomain: process.env.COMPANION_COOKIE_DOMAIN, streamingUpload: process.env.COMPANION_STREAMING_UPLOAD ? process.env.COMPANION_STREAMING_UPLOAD === 'true' : undefined, - deferredUploadLength: process.env.COMPANION_DEFERRED_UPLOAD_LENGTH ? process.env.COMPANION_DEFERRED_UPLOAD_LENGTH === 'true' : true, + tusDeferredUploadLength: process.env.COMPANION_TUS_DEFERRED_UPLOAD_LENGTH ? process.env.COMPANION_TUS_DEFERRED_UPLOAD_LENGTH === 'true' : true, maxFileSize: process.env.COMPANION_MAX_FILE_SIZE ? parseInt(process.env.COMPANION_MAX_FILE_SIZE, 10) : undefined, chunkSize: process.env.COMPANION_CHUNK_SIZE ? parseInt(process.env.COMPANION_CHUNK_SIZE, 10) : undefined, clientSocketConnectTimeout: process.env.COMPANION_CLIENT_SOCKET_CONNECT_TIMEOUT diff --git a/packages/@uppy/companion/test/mockserver.js b/packages/@uppy/companion/test/mockserver.js index c18d0f2098..329e4d2d2f 100644 --- a/packages/@uppy/companion/test/mockserver.js +++ b/packages/@uppy/companion/test/mockserver.js @@ -12,7 +12,7 @@ const defaultEnv = { COMPANION_HIDE_WELCOME: 'false', COMPANION_STREAMING_UPLOAD: 'true', - COMPANION_DEFERRED_UPLOAD_LENGTH: 'true', + COMPANION_TUS_DEFERRED_UPLOAD_LENGTH: 'true', COMPANION_ALLOW_LOCAL_URLS: 'false', COMPANION_PROTOCOL: 'http', From 04effbe0c69c6c3cc31c55433865edb52ef4d49e Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 8 Jan 2025 21:00:53 +0100 Subject: [PATCH 3/3] Add error message --- packages/@uppy/companion/src/server/Uploader.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/@uppy/companion/src/server/Uploader.js b/packages/@uppy/companion/src/server/Uploader.js index 3ba15f60dd..9f8014549d 100644 --- a/packages/@uppy/companion/src/server/Uploader.js +++ b/packages/@uppy/companion/src/server/Uploader.js @@ -554,6 +554,9 @@ class Uploader { if (this.options.companionOptions.tusDeferredUploadLength && !isFileStream) { tusOptions.uploadLengthDeferred = true } else { + if (!this.size) { + reject(new Error('tusDeferredUploadLength needs to be enabled if no file size is provided by the provider')) + } tusOptions.uploadLengthDeferred = false tusOptions.uploadSize = this.size }