diff options
Diffstat (limited to 'apps/files/lib')
-rw-r--r-- | apps/files/lib/App.php | 4 | ||||
-rw-r--r-- | apps/files/lib/Capabilities.php | 7 | ||||
-rw-r--r-- | apps/files/lib/Migration/Version2003Date20241021095629.php | 36 | ||||
-rw-r--r-- | apps/files/lib/Service/ChunkedUploadConfig.php | 30 |
4 files changed, 74 insertions, 3 deletions
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<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 index 00000000000..30d05fa12ad --- /dev/null +++ b/apps/files/lib/Migration/Version2003Date20241021095629.php @@ -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 index 00000000000..29661750f8b --- /dev/null +++ b/apps/files/lib/Service/ChunkedUploadConfig.php @@ -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); + } +} |