Skip to content

Commit ba3d67d

Browse files
committed
feat(files): Expose chunked upload config via capabilities
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 4d8d11d commit ba3d67d

File tree

9 files changed

+115
-4
lines changed

9 files changed

+115
-4
lines changed

apps/files/appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<name>Files</name>
1111
<summary>File Management</summary>
1212
<description>File Management</description>
13-
<version>2.3.0</version>
13+
<version>2.3.1</version>
1414
<licence>agpl</licence>
1515
<author>John Molakvoæ</author>
1616
<author>Robin Appelman</author>

apps/files/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@
6767
'OCA\\Files\\Listener\\SyncLivePhotosListener' => $baseDir . '/../lib/Listener/SyncLivePhotosListener.php',
6868
'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php',
6969
'OCA\\Files\\Migration\\Version12101Date20221011153334' => $baseDir . '/../lib/Migration/Version12101Date20221011153334.php',
70+
'OCA\\Files\\Migration\\Version2003Date20241021095629' => $baseDir . '/../lib/Migration/Version2003Date20241021095629.php',
7071
'OCA\\Files\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
7172
'OCA\\Files\\ResponseDefinitions' => $baseDir . '/../lib/ResponseDefinitions.php',
7273
'OCA\\Files\\Search\\FilesSearchProvider' => $baseDir . '/../lib/Search/FilesSearchProvider.php',
74+
'OCA\\Files\\Service\\ChunkedUploadConfig' => $baseDir . '/../lib/Service/ChunkedUploadConfig.php',
7375
'OCA\\Files\\Service\\DirectEditingService' => $baseDir . '/../lib/Service/DirectEditingService.php',
7476
'OCA\\Files\\Service\\LivePhotosService' => $baseDir . '/../lib/Service/LivePhotosService.php',
7577
'OCA\\Files\\Service\\OwnershipTransferService' => $baseDir . '/../lib/Service/OwnershipTransferService.php',

apps/files/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ class ComposerStaticInitFiles
8282
'OCA\\Files\\Listener\\SyncLivePhotosListener' => __DIR__ . '/..' . '/../lib/Listener/SyncLivePhotosListener.php',
8383
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
8484
'OCA\\Files\\Migration\\Version12101Date20221011153334' => __DIR__ . '/..' . '/../lib/Migration/Version12101Date20221011153334.php',
85+
'OCA\\Files\\Migration\\Version2003Date20241021095629' => __DIR__ . '/..' . '/../lib/Migration/Version2003Date20241021095629.php',
8586
'OCA\\Files\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
8687
'OCA\\Files\\ResponseDefinitions' => __DIR__ . '/..' . '/../lib/ResponseDefinitions.php',
8788
'OCA\\Files\\Search\\FilesSearchProvider' => __DIR__ . '/..' . '/../lib/Search/FilesSearchProvider.php',
89+
'OCA\\Files\\Service\\ChunkedUploadConfig' => __DIR__ . '/..' . '/../lib/Service/ChunkedUploadConfig.php',
8890
'OCA\\Files\\Service\\DirectEditingService' => __DIR__ . '/..' . '/../lib/Service/DirectEditingService.php',
8991
'OCA\\Files\\Service\\LivePhotosService' => __DIR__ . '/..' . '/../lib/Service/LivePhotosService.php',
9092
'OCA\\Files\\Service\\OwnershipTransferService' => __DIR__ . '/..' . '/../lib/Service/OwnershipTransferService.php',

apps/files/lib/App.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OCA\Files;
99

1010
use OC\NavigationManager;
11+
use OCA\Files\Service\ChunkedUploadConfig;
1112
use OCP\App\IAppManager;
1213
use OCP\IConfig;
1314
use OCP\IGroupManager;
@@ -44,9 +45,8 @@ public static function getNavigationManager(): INavigationManager {
4445
public static function extendJsConfig($settings): void {
4546
$appConfig = json_decode($settings['array']['oc_appconfig'], true);
4647

47-
$maxChunkSize = (int)Server::get(IConfig::class)->getAppValue('files', 'max_chunk_size', (string)(100 * 1024 * 1024));
4848
$appConfig['files'] = [
49-
'max_chunk_size' => $maxChunkSize
49+
'max_chunk_size' => ChunkedUploadConfig::getMaxChunkSize(),
5050
];
5151

5252
$settings['array']['oc_appconfig'] = json_encode($appConfig);

apps/files/lib/Capabilities.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OCA\Files;
99

1010
use OC\Files\FilenameValidator;
11+
use OCA\Files\Service\ChunkedUploadConfig;
1112
use OCP\Capabilities\ICapability;
1213

1314
class Capabilities implements ICapability {
@@ -20,7 +21,7 @@ public function __construct(
2021
/**
2122
* Return this classes capabilities
2223
*
23-
* @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>}}
24+
* @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}}}
2425
*/
2526
public function getCapabilities(): array {
2627
return [
@@ -33,6 +34,10 @@ public function getCapabilities(): array {
3334
'forbidden_filename_extensions' => $this->filenameValidator->getForbiddenExtensions(),
3435

3536
'bigfilechunking' => true,
37+
'chunked_upload' => [
38+
'max_size' => ChunkedUploadConfig::getMaxChunkSize(),
39+
'max_parallel_count' => ChunkedUploadConfig::getMaxParallelCount(),
40+
],
3641
],
3742
];
3843
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Files\Migration;
11+
12+
use Closure;
13+
use OCA\Files\Service\ChunkedUploadConfig;
14+
use OCP\DB\ISchemaWrapper;
15+
use OCP\IConfig;
16+
use OCP\Migration\IOutput;
17+
use OCP\Migration\SimpleMigrationStep;
18+
use OCP\Server;
19+
20+
class Version2003Date20241021095629 extends SimpleMigrationStep {
21+
/**
22+
* @param IOutput $output
23+
* @param Closure(): ISchemaWrapper $schemaClosure
24+
* @param array $options
25+
*/
26+
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
27+
$maxChunkSize = Server::get(IConfig::class)->getAppValue('files', 'max_chunk_size');
28+
if ($maxChunkSize === '') {
29+
// Skip if no value was configured before
30+
return;
31+
}
32+
33+
ChunkedUploadConfig::setMaxChunkSize((int)$maxChunkSize);
34+
Server::get(IConfig::class)->deleteAppValue('files', 'max_chunk_size');
35+
}
36+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Files\Service;
11+
12+
use OCP\IConfig;
13+
use OCP\Server;
14+
15+
class ChunkedUploadConfig {
16+
private const KEY_MAX_SIZE = 'files.chunked_upload.max_size';
17+
private const KEY_MAX_PARALLEL_COUNT = 'files.chunked_upload.max_parallel_count';
18+
19+
public static function getMaxChunkSize(): int {
20+
return Server::get(IConfig::class)->getSystemValueInt(self::KEY_MAX_SIZE, 100 * 1024 * 1024);
21+
}
22+
23+
public static function setMaxChunkSize(int $maxChunkSize): void {
24+
Server::get(IConfig::class)->setSystemValue(self::KEY_MAX_SIZE, $maxChunkSize);
25+
}
26+
27+
public static function getMaxParallelCount(): int {
28+
return Server::get(IConfig::class)->getSystemValueInt(self::KEY_MAX_PARALLEL_COUNT, 5);
29+
}
30+
}

apps/files/openapi.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"forbidden_filename_basenames",
3737
"forbidden_filename_characters",
3838
"forbidden_filename_extensions",
39+
"chunked_upload",
3940
"directEditing"
4041
],
4142
"properties": {
@@ -76,6 +77,23 @@
7677
"type": "string"
7778
}
7879
},
80+
"chunked_upload": {
81+
"type": "object",
82+
"required": [
83+
"max_size",
84+
"max_parallel_count"
85+
],
86+
"properties": {
87+
"max_size": {
88+
"type": "integer",
89+
"format": "int64"
90+
},
91+
"max_parallel_count": {
92+
"type": "integer",
93+
"format": "int64"
94+
}
95+
}
96+
},
7997
"directEditing": {
8098
"type": "object",
8199
"required": [

config/config.sample.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,4 +2556,22 @@
25562556
'/bin',
25572557
'/opt/bin',
25582558
],
2559+
2560+
/**
2561+
* The maximum chunk size to use for chunked uploads.
2562+
* A bigger chunk size results in higher throughput, but above 100 MiB there are only diminishing returns,
2563+
* while services like Cloudflare already limit to 100 MiB.
2564+
*
2565+
* Defaults to 100 MiB.
2566+
*/
2567+
'files.chunked_upload.max_size' => 100 * 1024 * 1024,
2568+
2569+
/**
2570+
* The maximum number of chunks uploaded in parallel during chunked uploads.
2571+
* A bigger count results in higher throughput, but will also consume more server workers,
2572+
* while the improvements diminish.
2573+
*
2574+
* Defaults to 5.
2575+
*/
2576+
'files.chunked_upload.max_parallel_count' => 5,
25592577
];

0 commit comments

Comments
 (0)