From: provokateurin Date: Thu, 17 Oct 2024 07:19:44 +0000 (+0200) Subject: feat(files): Expose chunked upload config via capabilities X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F48758%2Fhead;p=nextcloud-server.git feat(files): Expose chunked upload config via capabilities Signed-off-by: provokateurin --- diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml index ae999a03465..114ee85622b 100644 --- a/apps/files/appinfo/info.xml +++ b/apps/files/appinfo/info.xml @@ -10,7 +10,7 @@ Files File Management File Management - 2.3.0 + 2.3.1 agpl John Molakvoæ Robin Appelman diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php index 68cdabb3dcd..4be3f54c006 100644 --- a/apps/files/composer/composer/autoload_classmap.php +++ b/apps/files/composer/composer/autoload_classmap.php @@ -67,9 +67,11 @@ return array( 'OCA\\Files\\Listener\\SyncLivePhotosListener' => $baseDir . '/../lib/Listener/SyncLivePhotosListener.php', 'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php', 'OCA\\Files\\Migration\\Version12101Date20221011153334' => $baseDir . '/../lib/Migration/Version12101Date20221011153334.php', + 'OCA\\Files\\Migration\\Version2003Date20241021095629' => $baseDir . '/../lib/Migration/Version2003Date20241021095629.php', '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 ca88e773e4a..292768fc64f 100644 --- a/apps/files/composer/composer/autoload_static.php +++ b/apps/files/composer/composer/autoload_static.php @@ -82,9 +82,11 @@ class ComposerStaticInitFiles 'OCA\\Files\\Listener\\SyncLivePhotosListener' => __DIR__ . '/..' . '/../lib/Listener/SyncLivePhotosListener.php', 'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php', 'OCA\\Files\\Migration\\Version12101Date20221011153334' => __DIR__ . '/..' . '/../lib/Migration/Version12101Date20221011153334.php', + 'OCA\\Files\\Migration\\Version2003Date20241021095629' => __DIR__ . '/..' . '/../lib/Migration/Version2003Date20241021095629.php', '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 c8d2b786cd6..b6b0ffa6917 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,8 @@ class App { 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(), ]; $settings['array']['oc_appconfig'] = json_encode($appConfig); diff --git a/apps/files/lib/Capabilities.php b/apps/files/lib/Capabilities.php index fdbbdf63f22..d20d348a9f5 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 @@ class Capabilities implements ICapability { /** * 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 @@ class Capabilities implements ICapability { '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/Migration/Version2003Date20241021095629.php b/apps/files/lib/Migration/Version2003Date20241021095629.php new file mode 100644 index 00000000000..30d05fa12ad --- /dev/null +++ b/apps/files/lib/Migration/Version2003Date20241021095629.php @@ -0,0 +1,36 @@ +getAppValue('files', 'max_chunk_size'); + if ($maxChunkSize === '') { + // Skip if no value was configured before + return; + } + + ChunkedUploadConfig::setMaxChunkSize((int)$maxChunkSize); + Server::get(IConfig::class)->deleteAppValue('files', 'max_chunk_size'); + } +} diff --git a/apps/files/lib/Service/ChunkedUploadConfig.php b/apps/files/lib/Service/ChunkedUploadConfig.php new file mode 100644 index 00000000000..29661750f8b --- /dev/null +++ b/apps/files/lib/Service/ChunkedUploadConfig.php @@ -0,0 +1,30 @@ +getSystemValueInt(self::KEY_MAX_SIZE, 100 * 1024 * 1024); + } + + public static function setMaxChunkSize(int $maxChunkSize): void { + Server::get(IConfig::class)->setSystemValue(self::KEY_MAX_SIZE, $maxChunkSize); + } + + public static function getMaxParallelCount(): int { + return Server::get(IConfig::class)->getSystemValueInt(self::KEY_MAX_PARALLEL_COUNT, 5); + } +} diff --git a/apps/files/openapi.json b/apps/files/openapi.json index 5745f07889d..ded6ebd95e2 100644 --- a/apps/files/openapi.json +++ b/apps/files/openapi.json @@ -36,6 +36,7 @@ "forbidden_filename_basenames", "forbidden_filename_characters", "forbidden_filename_extensions", + "chunked_upload", "directEditing" ], "properties": { @@ -76,6 +77,23 @@ "type": "string" } }, + "chunked_upload": { + "type": "object", + "required": [ + "max_size", + "max_parallel_count" + ], + "properties": { + "max_size": { + "type": "integer", + "format": "int64" + }, + "max_parallel_count": { + "type": "integer", + "format": "int64" + } + } + }, "directEditing": { "type": "object", "required": [ diff --git a/config/config.sample.php b/config/config.sample.php index 709c1fb73c6..c8ee3c301ae 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -2556,4 +2556,22 @@ $CONFIG = [ '/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, ];