From 43d0cdb1342d0d9c7dc3ef63d1fa79d3f3993d5d Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 17 Oct 2024 09:51:15 +0200 Subject: [PATCH] feat: Respect parallel count config Signed-off-by: provokateurin --- lib/uploader.ts | 11 +++++++---- package-lock.json | 2 ++ package.json | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/uploader.ts b/lib/uploader.ts index f6d969cd..6e1a7801 100644 --- a/lib/uploader.ts +++ b/lib/uploader.ts @@ -22,6 +22,7 @@ import { isFileSystemFileEntry } from './utils/filesystem.js' import { Directory } from './utils/fileTree.js' import { t } from './utils/l10n.js' import logger from './utils/logger.js' +import { getCapabilities } from '@nextcloud/capabilities' export enum Status { IDLE = 0, @@ -29,9 +30,6 @@ export enum Status { PAUSED = 2 } -// Maximum number of concurrent uploads -const MAX_CONCURRENCY = 5 - export class Uploader { // Initialized via setter in the constructor @@ -41,7 +39,12 @@ export class Uploader { // Global upload queue private _uploadQueue: Array = [] - private _jobQueue: PQueue = new PQueue({ concurrency: MAX_CONCURRENCY }) + private _jobQueue: PQueue = new PQueue({ + // Maximum number of concurrent uploads + // @ts-expect-error TS2339 Object has no defined properties + concurrency: getCapabilities().files?.chunked_upload?.max_parallel_count ?? 5, + }) + private _queueSize = 0 private _queueProgress = 0 private _queueStatus: Status = Status.IDLE diff --git a/package-lock.json b/package-lock.json index 6c5724fd..b695b178 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@nextcloud/auth": "^2.4.0", "@nextcloud/axios": "^2.5.1", + "@nextcloud/capabilities": "^1.2.0", "@nextcloud/dialogs": "^5.3.7", "@nextcloud/files": "^3.9.0", "@nextcloud/l10n": "^3.1.0", @@ -1590,6 +1591,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/@nextcloud/capabilities/-/capabilities-1.2.0.tgz", "integrity": "sha512-L1NQtOfHWzkfj0Ple1MEJt6HmOHWAi3y4qs+OnwSWexqJT0DtXTVPyRxi7ADyITwRxS5H9R/HMl6USAj4Nr1nQ==", + "license": "GPL-3.0-or-later", "dependencies": { "@nextcloud/initial-state": "^2.1.0" }, diff --git a/package.json b/package.json index 742a34e0..4a10dc23 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "dependencies": { "@nextcloud/auth": "^2.4.0", "@nextcloud/axios": "^2.5.1", + "@nextcloud/capabilities": "^1.2.0", "@nextcloud/dialogs": "^5.3.7", "@nextcloud/files": "^3.9.0", "@nextcloud/l10n": "^3.1.0",