Skip to content

Commit

Permalink
feat(files): Expose chunked upload config via capabilities
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Oct 17, 2024
1 parent 4100f58 commit f35c7b5
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions apps/files/lib/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion apps/files/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OCA\Files;

use OC\Files\FilenameValidator;
use OCA\Files\Service\ChunkedUploadConfig;
use OCP\Capabilities\ICapability;

class Capabilities implements ICapability {
Expand All @@ -20,7 +21,7 @@ public function __construct(
/**
* 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 [
Expand All @@ -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(),
],
],
];
}
Expand Down
23 changes: 23 additions & 0 deletions apps/files/lib/Service/ChunkedUploadConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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 {
public static function getMaxChunkSize(): int {
return Server::get(IConfig::class)->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);
}
}
18 changes: 18 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];

0 comments on commit f35c7b5

Please sign in to comment.