]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat(files): Expose chunked upload config via capabilities feat/files/chunked-upload-config-capabilities 48758/head
authorprovokateurin <kate@provokateurin.de>
Thu, 17 Oct 2024 07:19:44 +0000 (09:19 +0200)
committerprovokateurin <kate@provokateurin.de>
Mon, 21 Oct 2024 10:03:33 +0000 (12:03 +0200)
Signed-off-by: provokateurin <kate@provokateurin.de>
apps/files/appinfo/info.xml
apps/files/composer/composer/autoload_classmap.php
apps/files/composer/composer/autoload_static.php
apps/files/lib/App.php
apps/files/lib/Capabilities.php
apps/files/lib/Migration/Version2003Date20241021095629.php [new file with mode: 0644]
apps/files/lib/Service/ChunkedUploadConfig.php [new file with mode: 0644]
apps/files/openapi.json
config/config.sample.php

index ae999a03465a4d6d69c8be9e8c049e774ca50ef1..114ee85622b399115dfbc6b17dfc2255a8f779c6 100644 (file)
@@ -10,7 +10,7 @@
        <name>Files</name>
        <summary>File Management</summary>
        <description>File Management</description>
-       <version>2.3.0</version>
+       <version>2.3.1</version>
        <licence>agpl</licence>
        <author>John Molakvoæ</author>
        <author>Robin Appelman</author>
index 68cdabb3dcdab2e19e49aac22e8bc69d75a0240e..4be3f54c006b8a2db3570d2173392356b618e2e2 100644 (file)
@@ -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',
index ca88e773e4aa51590119e5d0f26a9f6f259048cb..292768fc64f00e375b932e932e7b7a9a0151dfb7 100644 (file)
@@ -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',
index c8d2b786cd604fc532d5ce266afefbf5694b04bf..b6b0ffa6917f69a0b9d4a619941b889766fc5489 100644 (file)
@@ -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);
index fdbbdf63f22b1b4253e2bbe2bb787563ae53a715..d20d348a9f5df971ac56fb980f7ba2a39566e7ad 100644 (file)
@@ -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<mixed>, forbidden_filenames: list<string>, forbidden_filename_basenames: list<string>, forbidden_filename_characters: list<string>, forbidden_filename_extensions: list<string>}}
+        * @return array{files: array{'$comment': ?string, bigfilechunking: bool, blacklisted_files: array<mixed>, forbidden_filenames: list<string>, forbidden_filename_basenames: list<string>, forbidden_filename_characters: list<string>, forbidden_filename_extensions: list<string>, 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 (file)
index 0000000..30d05fa
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\Files\Migration;
+
+use Closure;
+use OCA\Files\Service\ChunkedUploadConfig;
+use OCP\DB\ISchemaWrapper;
+use OCP\IConfig;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Server;
+
+class Version2003Date20241021095629 extends SimpleMigrationStep {
+       /**
+        * @param IOutput $output
+        * @param Closure(): ISchemaWrapper $schemaClosure
+        * @param array $options
+        */
+       public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
+               $maxChunkSize = Server::get(IConfig::class)->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 (file)
index 0000000..2966175
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\Files\Service;
+
+use OCP\IConfig;
+use OCP\Server;
+
+class ChunkedUploadConfig {
+       private const KEY_MAX_SIZE = 'files.chunked_upload.max_size';
+       private const KEY_MAX_PARALLEL_COUNT = 'files.chunked_upload.max_parallel_count';
+
+       public static function getMaxChunkSize(): int {
+               return Server::get(IConfig::class)->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);
+       }
+}
index 5745f07889d180d1edd55f31dff20a762388ce74..ded6ebd95e27b2f48f7daa72d6bec00b2e087e8e 100644 (file)
@@ -36,6 +36,7 @@
                             "forbidden_filename_basenames",
                             "forbidden_filename_characters",
                             "forbidden_filename_extensions",
+                            "chunked_upload",
                             "directEditing"
                         ],
                         "properties": {
                                     "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": [
index 709c1fb73c63a8a8033e45c6655530e875b6bf0d..c8ee3c301aec351659ff0f89b1af1dcb8abb07fd 100644 (file)
@@ -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,
 ];