From f35c7b569a9256822cf107962282ce90742878d0 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 17 Oct 2024 09:19:44 +0200 Subject: [PATCH] feat(files): Expose chunked upload config via capabilities Signed-off-by: provokateurin --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/files/lib/App.php | 5 ++-- apps/files/lib/Capabilities.php | 7 +++++- .../files/lib/Service/ChunkedUploadConfig.php | 23 +++++++++++++++++++ config/config.sample.php | 18 +++++++++++++++ 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 apps/files/lib/Service/ChunkedUploadConfig.php diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index 68cdabb3dcdab..0fe3f7402cf02 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -70,6 +70,7 @@ 'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', 'OCA\\Files\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php', 'OCA\\Files\\Search\\FilesSearchProvider' => $baseDir . '/../lib/Search/FilesSearchProvider.php', + 'OCA\\Files\\Service\\ChunkedUploadConfig' => $baseDir . '/../lib/Service/ChunkedUploadConfig.php', 'OCA\\Files\\Service\\DirectEditingService' => $baseDir . '/../lib/Service/DirectEditingService.php', 'OCA\\Files\\Service\\LivePhotosService' => $baseDir . '/../lib/Service/LivePhotosService.php', 'OCA\\Files\\Service\\OwnershipTransferService' => $baseDir . '/../lib/Service/OwnershipTransferService.php', diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php index ca88e773e4aa5..8876b77cbcc8f 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -85,6 +85,7 @@ class ComposerStaticInitFiles 'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', 'OCA\\Files\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php', 'OCA\\Files\\Search\\FilesSearchProvider' => __DIR__ . '/..' . '/../lib/Search/FilesSearchProvider.php', + 'OCA\\Files\\Service\\ChunkedUploadConfig' => __DIR__ . '/..' . '/../lib/Service/ChunkedUploadConfig.php', 'OCA\\Files\\Service\\DirectEditingService' => __DIR__ . '/..' . '/../lib/Service/DirectEditingService.php', 'OCA\\Files\\Service\\LivePhotosService' => __DIR__ . '/..' . '/../lib/Service/LivePhotosService.php', 'OCA\\Files\\Service\\OwnershipTransferService' => __DIR__ . '/..' . '/../lib/Service/OwnershipTransferService.php', diff --git a/apps/files/lib/App.php b/apps/files/lib/App.php index c8d2b786cd604..4c6b41a8d8af6 100644 --- a/apps/files/lib/App.php +++ b/apps/files/lib/App.php @@ -8,6 +8,7 @@ namespace OCA\Files; use OC\NavigationManager; +use OCA\Files\Service\ChunkedUploadConfig; use OCP\App\IAppManager; use OCP\IConfig; use OCP\IGroupManager; @@ -44,9 +45,9 @@ public static function getNavigationManager(): INavigationManager { public static function extendJsConfig($settings): void { $appConfig = json_decode($settings['array']['oc_appconfig'], true); - $maxChunkSize = (int)Server::get(IConfig::class)->getAppValue('files', 'max_chunk_size', (string)(100 * 1024 * 1024)); $appConfig['files'] = [ - 'max_chunk_size' => $maxChunkSize + 'max_chunk_size' => ChunkedUploadConfig::getMaxChunkSize(), + 'max_parallel_count' => ChunkedUploadConfig::getMaxParallelCount(), ]; $settings['array']['oc_appconfig'] = json_encode($appConfig); diff --git a/apps/files/lib/Capabilities.php b/apps/files/lib/Capabilities.php index fdbbdf63f22b1..d20d348a9f5df 100644 --- a/apps/files/lib/Capabilities.php +++ b/apps/files/lib/Capabilities.php @@ -8,6 +8,7 @@ namespace OCA\Files; use OC\Files\FilenameValidator; +use OCA\Files\Service\ChunkedUploadConfig; use OCP\Capabilities\ICapability; class Capabilities implements ICapability { @@ -20,7 +21,7 @@ public function __construct( /** * Return this classes capabilities * - * @return array{files: array{'$comment': ?string, bigfilechunking: bool, blacklisted_files: array, forbidden_filenames: list, forbidden_filename_basenames: list, forbidden_filename_characters: list, forbidden_filename_extensions: list}} + * @return array{files: array{'$comment': ?string, bigfilechunking: bool, blacklisted_files: array, forbidden_filenames: list, forbidden_filename_basenames: list, forbidden_filename_characters: list, forbidden_filename_extensions: list, chunked_upload: array{max_size: int, max_parallel_count: int}}} */ public function getCapabilities(): array { return [ @@ -33,6 +34,10 @@ public function getCapabilities(): array { 'forbidden_filename_extensions' => $this->filenameValidator->getForbiddenExtensions(), 'bigfilechunking' => true, + 'chunked_upload' => [ + 'max_size' => ChunkedUploadConfig::getMaxChunkSize(), + 'max_parallel_count' => ChunkedUploadConfig::getMaxParallelCount(), + ], ], ]; } diff --git a/apps/files/lib/Service/ChunkedUploadConfig.php b/apps/files/lib/Service/ChunkedUploadConfig.php new file mode 100644 index 0000000000000..69ad9842ef499 --- /dev/null +++ b/apps/files/lib/Service/ChunkedUploadConfig.php @@ -0,0 +1,23 @@ +getSystemValueInt('files.chunked_upload.max_size', 100 * 1024 * 1024); + } + + public static function getMaxParallelCount(): int { + return Server::get(IConfig::class)->getSystemValueInt('files.chunked_upload.max_parallel_count', 5); + } +} diff --git a/config/config.sample.php b/config/config.sample.php index 21a77a8cbf646..b30ab537fff2f 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -2549,4 +2549,22 @@ '/bin', '/opt/bin', ], + +/** + * The maximum chunk size to use for chunked uploads. + * A bigger chunk size results in higher throughput, but above 100 MiB there are only diminishing returns, + * while services like Cloudflare already limit to 100 MiB. + * + * Defaults to 100 MiB. + */ +'files.chunked_upload.max_size' => 100 * 1024 * 1024, + +/** + * The maximum number of chunks uploaded in parallel during chunked uploads. + * A bigger count results in higher throughput, but will also consume more server workers, + * while the improvements diminish. + * + * Defaults to 5. + */ +'files.chunked_upload.max_parallel_count' => 5, ];