Skip to content

Commit 3da9905

Browse files
Merge pull request #56717 from nextcloud/enh/noid/taskpro-optional-watermarking
Add a boolean 'addWatermarking' attribute to taskprocessing tasks
2 parents bb1451f + b4f7fe2 commit 3da9905

File tree

14 files changed

+159
-10
lines changed

14 files changed

+159
-10
lines changed

core/Controller/TaskProcessingApiController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public function taskTypes(): DataResponse {
148148
* @param string $customId An arbitrary identifier for the task
149149
* @param string|null $webhookUri URI to be requested when the task finishes
150150
* @param string|null $webhookMethod Method used for the webhook request (HTTP:GET, HTTP:POST, HTTP:PUT, HTTP:DELETE or AppAPI:APP_ID:GET, AppAPI:APP_ID:POST...)
151+
* @param bool $includeWatermark Whether to include a watermark in the output file or not
151152
* @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_BAD_REQUEST|Http::STATUS_PRECONDITION_FAILED|Http::STATUS_UNAUTHORIZED, array{message: string}, array{}>
152153
*
153154
* 200: Task scheduled successfully
@@ -160,11 +161,12 @@ public function taskTypes(): DataResponse {
160161
#[ApiRoute(verb: 'POST', url: '/schedule', root: '/taskprocessing')]
161162
public function schedule(
162163
array $input, string $type, string $appId, string $customId = '',
163-
?string $webhookUri = null, ?string $webhookMethod = null,
164+
?string $webhookUri = null, ?string $webhookMethod = null, bool $includeWatermark = true,
164165
): DataResponse {
165166
$task = new Task($type, $input, $appId, $this->userId, $customId);
166167
$task->setWebhookUri($webhookUri);
167168
$task->setWebhookMethod($webhookMethod);
169+
$task->setIncludeWatermark($includeWatermark);
168170
try {
169171
$this->taskProcessingManager->scheduleTask($task);
170172

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OC\Core\Migrations;
10+
11+
use Closure;
12+
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\Types;
14+
use OCP\Migration\Attributes\AddColumn;
15+
use OCP\Migration\Attributes\ColumnType;
16+
use OCP\Migration\IOutput;
17+
use OCP\Migration\SimpleMigrationStep;
18+
19+
#[AddColumn(table: 'taskprocessing_tasks', name: 'include_watermark', type: ColumnType::SMALLINT)]
20+
class Version33000Date20251126152410 extends SimpleMigrationStep {
21+
22+
/**
23+
* @param IOutput $output
24+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
25+
* @param array $options
26+
* @return null|ISchemaWrapper
27+
*/
28+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
29+
/** @var ISchemaWrapper $schema */
30+
$schema = $schemaClosure();
31+
32+
if ($schema->hasTable('taskprocessing_tasks')) {
33+
$table = $schema->getTable('taskprocessing_tasks');
34+
if (!$table->hasColumn('include_watermark')) {
35+
$table->addColumn('include_watermark', Types::SMALLINT, [
36+
'notnull' => true,
37+
'default' => 1,
38+
'unsigned' => true,
39+
]);
40+
return $schema;
41+
}
42+
}
43+
44+
return null;
45+
}
46+
}

core/ResponseDefinitions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
* startedAt: ?int,
212212
* endedAt: ?int,
213213
* allowCleanup: bool,
214+
* includeWatermark: bool,
214215
* }
215216
*
216217
* @psalm-type CoreProfileAction = array{

core/openapi-ex_app.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@
165165
"scheduledAt",
166166
"startedAt",
167167
"endedAt",
168-
"allowCleanup"
168+
"allowCleanup",
169+
"includeWatermark"
169170
],
170171
"properties": {
171172
"id": {
@@ -239,6 +240,9 @@
239240
},
240241
"allowCleanup": {
241242
"type": "boolean"
243+
},
244+
"includeWatermark": {
245+
"type": "boolean"
242246
}
243247
}
244248
}

core/openapi-full.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@
659659
"scheduledAt",
660660
"startedAt",
661661
"endedAt",
662-
"allowCleanup"
662+
"allowCleanup",
663+
"includeWatermark"
663664
],
664665
"properties": {
665666
"id": {
@@ -733,6 +734,9 @@
733734
},
734735
"allowCleanup": {
735736
"type": "boolean"
737+
},
738+
"includeWatermark": {
739+
"type": "boolean"
736740
}
737741
}
738742
},
@@ -4944,6 +4948,11 @@
49444948
"nullable": true,
49454949
"default": null,
49464950
"description": "Method used for the webhook request (HTTP:GET, HTTP:POST, HTTP:PUT, HTTP:DELETE or AppAPI:APP_ID:GET, AppAPI:APP_ID:POST...)"
4951+
},
4952+
"includeWatermark": {
4953+
"type": "boolean",
4954+
"default": true,
4955+
"description": "Whether to include a watermark in the output file or not"
49474956
}
49484957
}
49494958
}

core/openapi.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@
659659
"scheduledAt",
660660
"startedAt",
661661
"endedAt",
662-
"allowCleanup"
662+
"allowCleanup",
663+
"includeWatermark"
663664
],
664665
"properties": {
665666
"id": {
@@ -733,6 +734,9 @@
733734
},
734735
"allowCleanup": {
735736
"type": "boolean"
737+
},
738+
"includeWatermark": {
739+
"type": "boolean"
736740
}
737741
}
738742
},
@@ -4944,6 +4948,11 @@
49444948
"nullable": true,
49454949
"default": null,
49464950
"description": "Method used for the webhook request (HTTP:GET, HTTP:POST, HTTP:PUT, HTTP:DELETE or AppAPI:APP_ID:GET, AppAPI:APP_ID:POST...)"
4951+
},
4952+
"includeWatermark": {
4953+
"type": "boolean",
4954+
"default": true,
4955+
"description": "Whether to include a watermark in the output file or not"
49474956
}
49484957
}
49494958
}

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@
875875
'OCP\\TaskProcessing\\IManager' => $baseDir . '/lib/public/TaskProcessing/IManager.php',
876876
'OCP\\TaskProcessing\\IProvider' => $baseDir . '/lib/public/TaskProcessing/IProvider.php',
877877
'OCP\\TaskProcessing\\ISynchronousProvider' => $baseDir . '/lib/public/TaskProcessing/ISynchronousProvider.php',
878+
'OCP\\TaskProcessing\\ISynchronousWatermarkingProvider' => $baseDir . '/lib/public/TaskProcessing/ISynchronousWatermarkingProvider.php',
878879
'OCP\\TaskProcessing\\ITaskType' => $baseDir . '/lib/public/TaskProcessing/ITaskType.php',
879880
'OCP\\TaskProcessing\\ITriggerableProvider' => $baseDir . '/lib/public/TaskProcessing/ITriggerableProvider.php',
880881
'OCP\\TaskProcessing\\ShapeDescriptor' => $baseDir . '/lib/public/TaskProcessing/ShapeDescriptor.php',
@@ -1536,6 +1537,7 @@
15361537
'OC\\Core\\Migrations\\Version33000Date20251023110529' => $baseDir . '/core/Migrations/Version33000Date20251023110529.php',
15371538
'OC\\Core\\Migrations\\Version33000Date20251023120529' => $baseDir . '/core/Migrations/Version33000Date20251023120529.php',
15381539
'OC\\Core\\Migrations\\Version33000Date20251106131209' => $baseDir . '/core/Migrations/Version33000Date20251106131209.php',
1540+
'OC\\Core\\Migrations\\Version33000Date20251126152410' => $baseDir . '/core/Migrations/Version33000Date20251126152410.php',
15391541
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
15401542
'OC\\Core\\ResponseDefinitions' => $baseDir . '/core/ResponseDefinitions.php',
15411543
'OC\\Core\\Service\\CronService' => $baseDir . '/core/Service/CronService.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
916916
'OCP\\TaskProcessing\\IManager' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/IManager.php',
917917
'OCP\\TaskProcessing\\IProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/IProvider.php',
918918
'OCP\\TaskProcessing\\ISynchronousProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ISynchronousProvider.php',
919+
'OCP\\TaskProcessing\\ISynchronousWatermarkingProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ISynchronousWatermarkingProvider.php',
919920
'OCP\\TaskProcessing\\ITaskType' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ITaskType.php',
920921
'OCP\\TaskProcessing\\ITriggerableProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ITriggerableProvider.php',
921922
'OCP\\TaskProcessing\\ShapeDescriptor' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ShapeDescriptor.php',
@@ -1577,6 +1578,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
15771578
'OC\\Core\\Migrations\\Version33000Date20251023110529' => __DIR__ . '/../../..' . '/core/Migrations/Version33000Date20251023110529.php',
15781579
'OC\\Core\\Migrations\\Version33000Date20251023120529' => __DIR__ . '/../../..' . '/core/Migrations/Version33000Date20251023120529.php',
15791580
'OC\\Core\\Migrations\\Version33000Date20251106131209' => __DIR__ . '/../../..' . '/core/Migrations/Version33000Date20251106131209.php',
1581+
'OC\\Core\\Migrations\\Version33000Date20251126152410' => __DIR__ . '/../../..' . '/core/Migrations/Version33000Date20251126152410.php',
15801582
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
15811583
'OC\\Core\\ResponseDefinitions' => __DIR__ . '/../../..' . '/core/ResponseDefinitions.php',
15821584
'OC\\Core\\Service\\CronService' => __DIR__ . '/../../..' . '/core/Service/CronService.php',

lib/private/TaskProcessing/Db/Task.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
* @method int getAllowCleanup()
5050
* @method setUserFacingErrorMessage(null|string $message)
5151
* @method null|string getUserFacingErrorMessage()
52+
* @method setIncludeWatermark(int $includeWatermark)
53+
* @method int getIncludeWatermark()
5254
*/
5355
class Task extends Entity {
5456
protected $lastUpdated;
@@ -69,16 +71,17 @@ class Task extends Entity {
6971
protected $endedAt;
7072
protected $allowCleanup;
7173
protected $userFacingErrorMessage;
74+
protected $includeWatermark;
7275

7376
/**
7477
* @var string[]
7578
*/
76-
public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'custom_id', 'completion_expected_at', 'error_message', 'progress', 'webhook_uri', 'webhook_method', 'scheduled_at', 'started_at', 'ended_at', 'allow_cleanup', 'user_facing_error_message'];
79+
public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'custom_id', 'completion_expected_at', 'error_message', 'progress', 'webhook_uri', 'webhook_method', 'scheduled_at', 'started_at', 'ended_at', 'allow_cleanup', 'user_facing_error_message', 'include_watermark'];
7780

7881
/**
7982
* @var string[]
8083
*/
81-
public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'customId', 'completionExpectedAt', 'errorMessage', 'progress', 'webhookUri', 'webhookMethod', 'scheduledAt', 'startedAt', 'endedAt', 'allowCleanup', 'userFacingErrorMessage'];
84+
public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'customId', 'completionExpectedAt', 'errorMessage', 'progress', 'webhookUri', 'webhookMethod', 'scheduledAt', 'startedAt', 'endedAt', 'allowCleanup', 'userFacingErrorMessage', 'includeWatermark'];
8285

8386

8487
public function __construct() {
@@ -102,6 +105,7 @@ public function __construct() {
102105
$this->addType('endedAt', 'integer');
103106
$this->addType('allowCleanup', 'integer');
104107
$this->addType('userFacingErrorMessage', 'string');
108+
$this->addType('includeWatermark', 'integer');
105109
}
106110

107111
public function toRow(): array {
@@ -132,6 +136,7 @@ public static function fromPublicTask(OCPTask $task): self {
132136
'endedAt' => $task->getEndedAt(),
133137
'allowCleanup' => $task->getAllowCleanup() ? 1 : 0,
134138
'userFacingErrorMessage' => $task->getUserFacingErrorMessage(),
139+
'includeWatermark' => $task->getIncludeWatermark() ? 1 : 0,
135140
]);
136141
return $taskEntity;
137142
}
@@ -156,6 +161,7 @@ public function toPublicTask(): OCPTask {
156161
$task->setEndedAt($this->getEndedAt());
157162
$task->setAllowCleanup($this->getAllowCleanup() !== 0);
158163
$task->setUserFacingErrorMessage($this->getUserFacingErrorMessage());
164+
$task->setIncludeWatermark($this->getIncludeWatermark() !== 0);
159165
return $task;
160166
}
161167
}

lib/private/TaskProcessing/Manager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
use OCP\TaskProcessing\IManager;
5757
use OCP\TaskProcessing\IProvider;
5858
use OCP\TaskProcessing\ISynchronousProvider;
59+
use OCP\TaskProcessing\ISynchronousWatermarkingProvider;
5960
use OCP\TaskProcessing\ITaskType;
6061
use OCP\TaskProcessing\ITriggerableProvider;
6162
use OCP\TaskProcessing\ShapeDescriptor;
@@ -1039,7 +1040,11 @@ public function processTask(Task $task, ISynchronousProvider $provider): bool {
10391040
}
10401041
try {
10411042
$this->setTaskStatus($task, Task::STATUS_RUNNING);
1042-
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->setTaskProgress($task->getId(), $progress));
1043+
if ($provider instanceof ISynchronousWatermarkingProvider) {
1044+
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->setTaskProgress($task->getId(), $progress), $task->getIncludeWatermark());
1045+
} else {
1046+
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->setTaskProgress($task->getId(), $progress));
1047+
}
10431048
} catch (ProcessingException $e) {
10441049
$this->logger->warning('Failed to process a TaskProcessing task with synchronous provider ' . $provider->getId(), ['exception' => $e]);
10451050
$userFacingErrorMessage = $e instanceof UserFacingProcessingException ? $e->getUserFacingMessage() : null;

0 commit comments

Comments
 (0)