From ac9700f9b5fec9bcfa6c04023b704bc6005ffbaa Mon Sep 17 00:00:00 2001 From: Montassar Ghanmy Date: Thu, 19 Sep 2024 17:39:57 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20big=20file=20(with=20multi?= =?UTF-8?q?ple=20chunks)=20download=20(#653)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/services/storage/storage-service.ts | 14 +++++--------- .../features/files/services/file-upload-service.ts | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tdrive/backend/node/src/core/platform/services/storage/storage-service.ts b/tdrive/backend/node/src/core/platform/services/storage/storage-service.ts index 16aa9fd3..2618b8e5 100644 --- a/tdrive/backend/node/src/core/platform/services/storage/storage-service.ts +++ b/tdrive/backend/node/src/core/platform/services/storage/storage-service.ts @@ -137,21 +137,19 @@ export default class StorageService extends TdriveService implements try { // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; - const chunks = options?.totalChunks || 1; let count = 1; - //check that the file a really exists + // Check if the first chunk or file exists await self._read(options?.totalChunks ? `${path}/chunk${count}` : path); - let stream: any; async function factory(callback: (err?: Error, stream?: Stream) => unknown) { if (count > chunks) { callback(); return; } - let decipher: Decipher; + let decipher: Decipher | undefined; if (options?.encryptionKey) { const [key, iv] = options.encryptionKey.split("."); decipher = createDecipheriv(options.encryptionAlgo || this.algorithm, key, iv); @@ -161,17 +159,15 @@ export default class StorageService extends TdriveService implements count += 1; try { - stream = await self._read(chunk); + let stream = await self._read(chunk); // Read the chunk if (decipher) { - stream = stream.pipe(decipher); + stream = stream.pipe(decipher); // Apply decipher if necessary } - callback(null, stream); + callback(null, stream); // Return the stream only once } catch (err) { logger.error(err); callback(err, null); } - callback(null, stream); - return; } return new Multistream(factory); diff --git a/tdrive/frontend/src/app/features/files/services/file-upload-service.ts b/tdrive/frontend/src/app/features/files/services/file-upload-service.ts index 8415074f..df93111a 100644 --- a/tdrive/frontend/src/app/features/files/services/file-upload-service.ts +++ b/tdrive/frontend/src/app/features/files/services/file-upload-service.ts @@ -303,7 +303,7 @@ class FileUploadService { return new Resumable({ target, headers, - chunkSize: chunkSize || 50000000, + chunkSize: chunkSize || 5000000, testChunks: testChunks || false, simultaneousUploads: simultaneousUploads || 5, maxChunkRetries: maxChunkRetries || 2,