Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/Controller/TaskProcessingApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public function taskTypes(): DataResponse {
* @param string $customId An arbitrary identifier for the task
* @param string|null $webhookUri URI to be requested when the task finishes
* @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...)
* @param bool $includeWatermark Whether to include a watermark in the output file or not
* @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{}>
*
* 200: Task scheduled successfully
Expand All @@ -160,11 +161,12 @@ public function taskTypes(): DataResponse {
#[ApiRoute(verb: 'POST', url: '/schedule', root: '/taskprocessing')]
public function schedule(
array $input, string $type, string $appId, string $customId = '',
?string $webhookUri = null, ?string $webhookMethod = null,
?string $webhookUri = null, ?string $webhookMethod = null, bool $includeWatermark = true,
): DataResponse {
$task = new Task($type, $input, $appId, $this->userId, $customId);
$task->setWebhookUri($webhookUri);
$task->setWebhookMethod($webhookMethod);
$task->setIncludeWatermark($includeWatermark);
try {
$this->taskProcessingManager->scheduleTask($task);

Expand Down
46 changes: 46 additions & 0 deletions core/Migrations/Version33000Date20251126152410.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Migrations;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\Attributes\AddColumn;
use OCP\Migration\Attributes\ColumnType;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

#[AddColumn(table: 'taskprocessing_tasks', name: 'include_watermark', type: ColumnType::SMALLINT)]
class Version33000Date20251126152410 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('taskprocessing_tasks')) {
$table = $schema->getTable('taskprocessing_tasks');
if (!$table->hasColumn('include_watermark')) {
$table->addColumn('include_watermark', Types::SMALLINT, [
'notnull' => true,
'default' => 1,
'unsigned' => true,
]);
return $schema;
}
}

return null;
}
}
1 change: 1 addition & 0 deletions core/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
* startedAt: ?int,
* endedAt: ?int,
* allowCleanup: bool,
* includeWatermark: bool,
* }
*
* @psalm-type CoreProfileAction = array{
Expand Down
6 changes: 5 additions & 1 deletion core/openapi-ex_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
"scheduledAt",
"startedAt",
"endedAt",
"allowCleanup"
"allowCleanup",
"includeWatermark"
],
"properties": {
"id": {
Expand Down Expand Up @@ -239,6 +240,9 @@
},
"allowCleanup": {
"type": "boolean"
},
"includeWatermark": {
"type": "boolean"
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion core/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@
"scheduledAt",
"startedAt",
"endedAt",
"allowCleanup"
"allowCleanup",
"includeWatermark"
],
"properties": {
"id": {
Expand Down Expand Up @@ -733,6 +734,9 @@
},
"allowCleanup": {
"type": "boolean"
},
"includeWatermark": {
"type": "boolean"
}
}
},
Expand Down Expand Up @@ -4944,6 +4948,11 @@
"nullable": true,
"default": null,
"description": "Method used for the webhook request (HTTP:GET, HTTP:POST, HTTP:PUT, HTTP:DELETE or AppAPI:APP_ID:GET, AppAPI:APP_ID:POST...)"
},
"includeWatermark": {
"type": "boolean",
"default": true,
"description": "Whether to include a watermark in the output file or not"
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@
"scheduledAt",
"startedAt",
"endedAt",
"allowCleanup"
"allowCleanup",
"includeWatermark"
],
"properties": {
"id": {
Expand Down Expand Up @@ -733,6 +734,9 @@
},
"allowCleanup": {
"type": "boolean"
},
"includeWatermark": {
"type": "boolean"
}
}
},
Expand Down Expand Up @@ -4944,6 +4948,11 @@
"nullable": true,
"default": null,
"description": "Method used for the webhook request (HTTP:GET, HTTP:POST, HTTP:PUT, HTTP:DELETE or AppAPI:APP_ID:GET, AppAPI:APP_ID:POST...)"
},
"includeWatermark": {
"type": "boolean",
"default": true,
"description": "Whether to include a watermark in the output file or not"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@
'OCP\\TaskProcessing\\IManager' => $baseDir . '/lib/public/TaskProcessing/IManager.php',
'OCP\\TaskProcessing\\IProvider' => $baseDir . '/lib/public/TaskProcessing/IProvider.php',
'OCP\\TaskProcessing\\ISynchronousProvider' => $baseDir . '/lib/public/TaskProcessing/ISynchronousProvider.php',
'OCP\\TaskProcessing\\ISynchronousWatermarkingProvider' => $baseDir . '/lib/public/TaskProcessing/ISynchronousWatermarkingProvider.php',
'OCP\\TaskProcessing\\ITaskType' => $baseDir . '/lib/public/TaskProcessing/ITaskType.php',
'OCP\\TaskProcessing\\ITriggerableProvider' => $baseDir . '/lib/public/TaskProcessing/ITriggerableProvider.php',
'OCP\\TaskProcessing\\ShapeDescriptor' => $baseDir . '/lib/public/TaskProcessing/ShapeDescriptor.php',
Expand Down Expand Up @@ -1536,6 +1537,7 @@
'OC\\Core\\Migrations\\Version33000Date20251023110529' => $baseDir . '/core/Migrations/Version33000Date20251023110529.php',
'OC\\Core\\Migrations\\Version33000Date20251023120529' => $baseDir . '/core/Migrations/Version33000Date20251023120529.php',
'OC\\Core\\Migrations\\Version33000Date20251106131209' => $baseDir . '/core/Migrations/Version33000Date20251106131209.php',
'OC\\Core\\Migrations\\Version33000Date20251126152410' => $baseDir . '/core/Migrations/Version33000Date20251126152410.php',
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
'OC\\Core\\ResponseDefinitions' => $baseDir . '/core/ResponseDefinitions.php',
'OC\\Core\\Service\\CronService' => $baseDir . '/core/Service/CronService.php',
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\TaskProcessing\\IManager' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/IManager.php',
'OCP\\TaskProcessing\\IProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/IProvider.php',
'OCP\\TaskProcessing\\ISynchronousProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ISynchronousProvider.php',
'OCP\\TaskProcessing\\ISynchronousWatermarkingProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ISynchronousWatermarkingProvider.php',
'OCP\\TaskProcessing\\ITaskType' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ITaskType.php',
'OCP\\TaskProcessing\\ITriggerableProvider' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ITriggerableProvider.php',
'OCP\\TaskProcessing\\ShapeDescriptor' => __DIR__ . '/../../..' . '/lib/public/TaskProcessing/ShapeDescriptor.php',
Expand Down Expand Up @@ -1577,6 +1578,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Migrations\\Version33000Date20251023110529' => __DIR__ . '/../../..' . '/core/Migrations/Version33000Date20251023110529.php',
'OC\\Core\\Migrations\\Version33000Date20251023120529' => __DIR__ . '/../../..' . '/core/Migrations/Version33000Date20251023120529.php',
'OC\\Core\\Migrations\\Version33000Date20251106131209' => __DIR__ . '/../../..' . '/core/Migrations/Version33000Date20251106131209.php',
'OC\\Core\\Migrations\\Version33000Date20251126152410' => __DIR__ . '/../../..' . '/core/Migrations/Version33000Date20251126152410.php',
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
'OC\\Core\\ResponseDefinitions' => __DIR__ . '/../../..' . '/core/ResponseDefinitions.php',
'OC\\Core\\Service\\CronService' => __DIR__ . '/../../..' . '/core/Service/CronService.php',
Expand Down
10 changes: 8 additions & 2 deletions lib/private/TaskProcessing/Db/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
* @method int getAllowCleanup()
* @method setUserFacingErrorMessage(null|string $message)
* @method null|string getUserFacingErrorMessage()
* @method setIncludeWatermark(int $includeWatermark)
* @method int getIncludeWatermark()
*/
class Task extends Entity {
protected $lastUpdated;
Expand All @@ -69,16 +71,17 @@ class Task extends Entity {
protected $endedAt;
protected $allowCleanup;
protected $userFacingErrorMessage;
protected $includeWatermark;

/**
* @var string[]
*/
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'];
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'];

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


public function __construct() {
Expand All @@ -102,6 +105,7 @@ public function __construct() {
$this->addType('endedAt', 'integer');
$this->addType('allowCleanup', 'integer');
$this->addType('userFacingErrorMessage', 'string');
$this->addType('includeWatermark', 'integer');
}

public function toRow(): array {
Expand Down Expand Up @@ -132,6 +136,7 @@ public static function fromPublicTask(OCPTask $task): self {
'endedAt' => $task->getEndedAt(),
'allowCleanup' => $task->getAllowCleanup() ? 1 : 0,
'userFacingErrorMessage' => $task->getUserFacingErrorMessage(),
'includeWatermark' => $task->getIncludeWatermark() ? 1 : 0,
]);
return $taskEntity;
}
Expand All @@ -156,6 +161,7 @@ public function toPublicTask(): OCPTask {
$task->setEndedAt($this->getEndedAt());
$task->setAllowCleanup($this->getAllowCleanup() !== 0);
$task->setUserFacingErrorMessage($this->getUserFacingErrorMessage());
$task->setIncludeWatermark($this->getIncludeWatermark() !== 0);
return $task;
}
}
7 changes: 6 additions & 1 deletion lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use OCP\TaskProcessing\IManager;
use OCP\TaskProcessing\IProvider;
use OCP\TaskProcessing\ISynchronousProvider;
use OCP\TaskProcessing\ISynchronousWatermarkingProvider;
use OCP\TaskProcessing\ITaskType;
use OCP\TaskProcessing\ITriggerableProvider;
use OCP\TaskProcessing\ShapeDescriptor;
Expand Down Expand Up @@ -1039,7 +1040,11 @@ public function processTask(Task $task, ISynchronousProvider $provider): bool {
}
try {
$this->setTaskStatus($task, Task::STATUS_RUNNING);
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->setTaskProgress($task->getId(), $progress));
if ($provider instanceof ISynchronousWatermarkingProvider) {
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->setTaskProgress($task->getId(), $progress), $task->getIncludeWatermark());
} else {
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->setTaskProgress($task->getId(), $progress));
}
} catch (ProcessingException $e) {
$this->logger->warning('Failed to process a TaskProcessing task with synchronous provider ' . $provider->getId(), ['exception' => $e]);
$userFacingErrorMessage = $e instanceof UserFacingProcessingException ? $e->getUserFacingMessage() : null;
Expand Down
35 changes: 35 additions & 0 deletions lib/public/TaskProcessing/ISynchronousWatermarkingProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


namespace OCP\TaskProcessing;

use OCP\Files\File;
use OCP\TaskProcessing\Exception\ProcessingException;

/**
* This is the interface that is implemented by apps that
* implement a task processing provider that supports watermarking
* @since 33.0.0
*/
interface ISynchronousWatermarkingProvider extends ISynchronousProvider {

/**
* Returns the shape of optional output parameters
*
* @param null|string $userId The user that created the current task
* @param array<string, list<numeric|string|File>|numeric|string|File> $input The task input
* @param callable(float):bool $reportProgress Report the task progress. If this returns false, that means the task was cancelled and processing should be stopped.
* @param bool $includeWatermark Whether to include the watermark in the output files or not
* @psalm-return array<string, list<numeric|string>|numeric|string>
* @throws ProcessingException
* @since 33.0.0
*/
public function process(?string $userId, array $input, callable $reportProgress, bool $includeWatermark = true): array;
}
21 changes: 20 additions & 1 deletion lib/public/TaskProcessing/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ final class Task implements \JsonSerializable {

protected ?string $userFacingErrorMessage = null;

protected bool $includeWatermark = true;

/**
* @since 30.0.0
*/
Expand Down Expand Up @@ -277,7 +279,23 @@ final public function setAllowCleanup(bool $allowCleanup): void {
}

/**
* @psalm-return array{id: int, lastUpdated: int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array<string, list<numeric|string>|numeric|string>, output: ?array<string, list<numeric|string>|numeric|string>, customId: ?string, completionExpectedAt: ?int, progress: ?float, scheduledAt: ?int, startedAt: ?int, endedAt: ?int, allowCleanup: bool}
* @return bool
* @since 33.0.0
*/
final public function getIncludeWatermark(): bool {
return $this->includeWatermark;
}

/**
* @param bool $includeWatermark
* @since 33.0.0
*/
final public function setIncludeWatermark(bool $includeWatermark): void {
$this->includeWatermark = $includeWatermark;
}

/**
* @psalm-return array{id: int, lastUpdated: int, type: string, status: 'STATUS_CANCELLED'|'STATUS_FAILED'|'STATUS_SUCCESSFUL'|'STATUS_RUNNING'|'STATUS_SCHEDULED'|'STATUS_UNKNOWN', userId: ?string, appId: string, input: array<string, list<numeric|string>|numeric|string>, output: ?array<string, list<numeric|string>|numeric|string>, customId: ?string, completionExpectedAt: ?int, progress: ?float, scheduledAt: ?int, startedAt: ?int, endedAt: ?int, allowCleanup: bool, includeWatermark: bool}
* @since 30.0.0
*/
final public function jsonSerialize(): array {
Expand All @@ -297,6 +315,7 @@ final public function jsonSerialize(): array {
'startedAt' => $this->getStartedAt(),
'endedAt' => $this->getEndedAt(),
'allowCleanup' => $this->getAllowCleanup(),
'includeWatermark' => $this->getIncludeWatermark(),
];
}

Expand Down
11 changes: 10 additions & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,8 @@
"scheduledAt",
"startedAt",
"endedAt",
"allowCleanup"
"allowCleanup",
"includeWatermark"
],
"properties": {
"id": {
Expand Down Expand Up @@ -775,6 +776,9 @@
},
"allowCleanup": {
"type": "boolean"
},
"includeWatermark": {
"type": "boolean"
}
}
},
Expand Down Expand Up @@ -8475,6 +8479,11 @@
"nullable": true,
"default": null,
"description": "Method used for the webhook request (HTTP:GET, HTTP:POST, HTTP:PUT, HTTP:DELETE or AppAPI:APP_ID:GET, AppAPI:APP_ID:POST...)"
},
"includeWatermark": {
"type": "boolean",
"default": true,
"description": "Whether to include a watermark in the output file or not"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patch level
// when updating major/minor version number.

$OC_Version = [33, 0, 0, 4];
$OC_Version = [33, 0, 0, 5];

// The human-readable string
$OC_VersionString = '33.0.0 dev';
Expand Down
Loading